problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll a, b, n;
cin >> a >> b >> n;
ll res = ((a * n) / b) - a * (n / b);
if (b > 1e6) {
for (ll k = 0; k * b - 1 <= n; ++k) {
ll x = k * b - 1;
res = max(res, ((a * x) / b) - a * (x / b));
}
} else {
for (ll x = 0; x <= n; ++x) {
res = max(res, ((a * x) / b) - a * (x / b));
}
}
cout << res << "\n";
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll a, b, n;
cin >> a >> b >> n;
ll res = ((a * n) / b) - a * (n / b);
if (b > 1e6) {
for (ll k = 0; k * b - 1 <= n; ++k) {
ll x = k * b - 1;
res = max(res, ((a * x) / b) - a * (x / b));
}
} else {
for (ll x = 0; x <= min(n, 3 * b); ++x) {
res = max(res, ((a * x) / b) - a * (x / b));
}
}
cout << res << "\n";
return 0;
}
| replace | 22 | 23 | 22 | 23 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define _Max(a, b, c) Max(a, Max(b, c))
#define lop(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
/*
*
* Saroar Zahan Sojib
* Green University - Bangladesh (GUB)
*
*/
int main() {
set<long long> vec;
long long a, b, n, i, k;
cin >> a >> b >> n;
k = sqrt(n);
for (i = k; i <= n; i++) {
long long e, f, g;
e = floor((a * i) / b);
f = floor(i / b);
g = e - (a * f);
vec.insert(g);
}
long long max = 0;
for (auto x : vec) {
if (max < x) {
max = x;
}
}
cout << max << endl;
return 0;
}
| #include <bits/stdc++.h>
#define _Max(a, b, c) Max(a, Max(b, c))
#define lop(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
/*
*
* Saroar Zahan Sojib
* Green University - Bangladesh (GUB)
*
*/
int main() {
long long A, B, N;
cin >> A >> B >> N;
long long x = min(B - 1, N);
cout << (A * x) / B - A * (x / B) << endl;
return 0;
}
| replace | 12 | 30 | 12 | 16 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
ll res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve() {
double a, b, n;
cin >> a >> b >> n;
double max1 = INT_MIN;
for (double i = n; i >= 0; i--) {
max1 = max(max1, (ll)(floor((a * i) / b)) - a * floor(i / b));
}
cout << max1;
}
int main() {
fast();
solve();
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
ll res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve() {
double a, b, n;
cin >> a >> b >> n;
ll max1 = min(b - 1, n);
// for(double i=n;i>=0;i--){
ll m1 = (ll)(floor((a * (max1)) / b)) - a * floor((max1) / b);
//}
cout << m1;
}
int main() {
fast();
solve();
return 0;
}
| replace | 29 | 34 | 29 | 34 | TLE | |
p02696 | C++ | Time Limit Exceeded | // #include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #include "boost/multiprecision/cpp_int.hpp"
// typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9 + 7)
// #define i_7 998244353
#define i_5 i_7 - 2
ll mod(ll a) {
ll c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
typedef pair<ll, ll> l_l;
typedef pair<dd, dd> d_d;
ll inf = (ll)1E16;
#define rep(i, l, r) for (ll i = l; i <= r; i++)
#define pb push_back
ll max(ll a, ll b) {
if (a < b)
return b;
else
return a;
}
ll min(ll a, ll b) {
if (a > b)
return b;
else
return a;
}
void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]);
void Min(ll &pos, ll val) { pos = min(pos, val); }
void Add(ll &pos, ll val) { pos = mod(pos + val); }
dd EPS = 1E-9;
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(), v.end())
#define ERASE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define POSL(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define POSU(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
//////////////////////////
int main() {
fastio ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
if (b > n) {
cout << a * n / b << endl;
return 0;
} else if (b <= 1000000) {
rep(x, 0, n) { chmax(ans, a * x / b - a * (x / b)); }
} else {
ll x = b - 1;
chmax(ans, a * x / b - a * (x / b));
}
cout << ans << endl;
return 0;
}
| // #include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #include "boost/multiprecision/cpp_int.hpp"
// typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9 + 7)
// #define i_7 998244353
#define i_5 i_7 - 2
ll mod(ll a) {
ll c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
typedef pair<ll, ll> l_l;
typedef pair<dd, dd> d_d;
ll inf = (ll)1E16;
#define rep(i, l, r) for (ll i = l; i <= r; i++)
#define pb push_back
ll max(ll a, ll b) {
if (a < b)
return b;
else
return a;
}
ll min(ll a, ll b) {
if (a > b)
return b;
else
return a;
}
void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]);
void Min(ll &pos, ll val) { pos = min(pos, val); }
void Add(ll &pos, ll val) { pos = mod(pos + val); }
dd EPS = 1E-9;
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(), v.end())
#define ERASE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define POSL(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define POSU(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
//////////////////////////
int main() {
fastio ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
if (b > n) {
cout << a * n / b << endl;
return 0;
} else if (b <= 1000000) {
rep(x, 0, b) { chmax(ans, a * x / b - a * (x / b)); }
} else {
ll x = b - 1;
chmax(ans, a * x / b - a * (x / b));
}
cout << ans << endl;
return 0;
}
| replace | 73 | 74 | 73 | 74 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long mmax(long long a, long long b) {
if (a > b)
return a;
return b;
}
int main() {
long long a, b, n;
cin >> a >> b >> n;
if (n < b)
cout << a * n / b << endl;
else {
long long x, maxn = 0;
for (x = b - 1ll; x <= n; x += b)
maxn = mmax(maxn, a * x / b - a * (x / b));
cout << maxn << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long mmax(long long a, long long b) {
if (a > b)
return a;
return b;
}
int main() {
long long a, b, n;
cin >> a >> b >> n;
if (b == 1) {
cout << 0 << endl;
return 0;
}
if (n < b)
cout << a * n / b << endl;
else {
long long x, maxn = 0;
for (x = b - 1ll; x <= n; x += b)
maxn = mmax(maxn, a * x / b - a * (x / b));
cout << maxn << endl;
}
return 0;
} | insert | 13 | 13 | 13 | 18 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(25);
ll a, b, n;
cin >> a >> b >> n;
ll ans = -INF;
for (ll x = b - 1; x <= n; x += b) {
ll res1 = a * x / b;
ll res2 = x / b * a;
chmax(ans, res1 - res2);
}
ll x = n;
ll res1 = a * x / b;
ll res2 = x / b * a;
chmax(ans, res1 - res2);
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(25);
ll a, b, n;
cin >> a >> b >> n;
cout << a * min(b - 1, n) / b << '\n';
return 0;
} | replace | 40 | 51 | 40 | 41 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef int64_t i6;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) \
Sort(x); \
reverse(ALL(x))
template <typename V, typename T> T find_num(V v, T num) {
if (find(ALL(v), num) == v.end()) {
return false;
} else {
return true;
}
}
// π M_PI
// deg = rad*180/M_PI
ll num(ll a, ll b, ll i) {
ll ans = (int)(a * i / b) - a * (int)(i / b);
// cout << "a " << ans << endl;
return ans;
}
int main() {
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
if (n < b) {
std::vector<ll> v;
/*
rep2(i, n) {
v.push_back( num(a, b, i) );
}
ans = *max_element(ALL(v));*/
ans = num(a, b, n);
} else {
ll nn = b;
ll i = 2;
// std::vector<ll> v;
priority_queue<ll> q;
while (nn <= n) {
// v.push_back( num(a, b, nn-1) );
// v.push_back( num(a, b, nn) );
ll k = num(a, b, nn - 1); /*
if ( !q.empty() && k < q.top() ) {
break;
}*/
q.push(num(a, b, nn - 1));
q.push(num(a, b, nn));
nn = b * i;
i++;
}
ans = q.top();
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef int64_t i6;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) \
Sort(x); \
reverse(ALL(x))
template <typename V, typename T> T find_num(V v, T num) {
if (find(ALL(v), num) == v.end()) {
return false;
} else {
return true;
}
}
// π M_PI
// deg = rad*180/M_PI
ll num(ll a, ll b, ll i) {
ll ans = (int)(a * i / b) - a * (int)(i / b);
// cout << "a " << ans << endl;
return ans;
}
int main() {
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
if (n < b) {
std::vector<ll> v;
/*
rep2(i, n) {
v.push_back( num(a, b, i) );
}
ans = *max_element(ALL(v));*/
ans = num(a, b, n);
} else {
ll nn = b;
ll i = 2;
// std::vector<ll> v;
priority_queue<ll> q;
while (nn <= n) {
// v.push_back( num(a, b, nn-1) );
// v.push_back( num(a, b, nn) );
ll k = num(a, b, nn - 1);
if (!q.empty() && k < q.top()) {
break;
}
q.push(num(a, b, nn - 1));
q.push(num(a, b, nn));
nn = b * i;
i++;
}
ans = q.top();
}
cout << ans << endl;
return 0;
}
| replace | 51 | 55 | 51 | 55 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;
int main() {
int64_t a, b, n;
cin >> a >> b >> n;
int64_t m = 0;
rep(i, n / 2, n + 1) { m = max(m, ((a * i / b) - a * (i / b))); }
cout << m << endl;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;
int main() {
int64_t a, b, n;
cin >> a >> b >> n;
int64_t m = 0;
if (n >= b - 1)
m = a * (b - 1) / b;
else
m = a * n / b - a * (n / b);
cout << m << endl;
} | replace | 16 | 17 | 16 | 20 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう
#define rep(i, n) for (i = 1; i < n; i++)
typedef long long ll;
typedef long double ld;
const double pi = 3.1415926535;
const ll mod = 1000000007;
// 桁数指定 cout << fixed << setprecision(2)
int main() {
ld ans = 0;
ld a, b, n;
cin >> a >> b >> n;
int x = 1;
rep(x, min(b, n + 1)) {
ld sum = floorl(a * x / b) - a * floorl(x / b);
ans = max(ans, sum);
// cerr<<x<<sum<<endl;
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう
#define rep(i, n) for (i = 1; i < n; i++)
typedef long long ll;
typedef long double ld;
const double pi = 3.1415926535;
const ll mod = 1000000007;
// 桁数指定 cout << fixed << setprecision(2)
int main() {
ld ans = 0;
ld a, b, n;
cin >> a >> b >> n;
ll x = min(b - 1, n);
ld sum = floorl(a * x / b) - a * floorl(x / b);
ans = max(ans, sum);
cerr << x << sum << endl;
cout << ans;
} | replace | 14 | 20 | 14 | 19 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <deque> // deque
#include <iomanip> //setprecsion
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <utility> // pair, make_pair
#include <vector> // vector
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> //sin, cos, tan
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;
typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;
const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;
template <typename T> void fin(T a) {
cout << a << endl;
exit(0);
}
void Main() {
ll a, b, n;
cin >> a >> b >> n;
ll flag = 0;
ll x = 0;
while (1) {
x += 25000;
if (x >= n || ((a * x) / b) > ((x / b) * a)) {
ll ans = 0;
for (ll i = x - 25000 - 10; i <= n; i++) {
if (i <= 0)
continue;
flag = max((a * i) / b - a * (i / b), flag);
}
fin(flag);
}
}
}
// 前処理
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20); // 高精度少数表示
// cout << setfill('0') << internal << setw(4); 0埋め4桁
Main();
return 0;
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <deque> // deque
#include <iomanip> //setprecsion
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <utility> // pair, make_pair
#include <vector> // vector
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> //sin, cos, tan
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;
typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;
const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;
template <typename T> void fin(T a) {
cout << a << endl;
exit(0);
}
void Main() {
ll a, b, n;
cin >> a >> b >> n;
n = min(n, b - 1);
cout << a * n / b - a * (n / b) << endl;
}
// 前処理
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20); // 高精度少数表示
// cout << setfill('0') << internal << setw(4); 0埋め4桁
Main();
return 0;
}
| replace | 60 | 74 | 60 | 62 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long a, b, n;
cin >> a >> b >> n;
long ans = a / b - a * (1 / b);
for (long i = 0; i <= n; i++) {
long tmp = (a * i) / b - a * (i / b);
ans = max(ans, tmp);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long a, b, n;
cin >> a >> b >> n;
long x = min(b - 1, n);
cout << (a * x) / b << endl;
} | replace | 7 | 14 | 7 | 9 | TLE | |
p02696 | C++ | Time Limit Exceeded | /*
Coded and Decoded by : Yash Kapoor
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\n'
#define why (ll)1000000007
// #define why (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod) {
ll result = 1;
while (power) {
if (power % 2)
result = (result * base) % mod;
base = (base * base) % mod;
power /= 2;
}
return result;
}
ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }
ll solve() {
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
if (b - 1 > n) {
cout << (a * n) / b - a * (n / b);
return 0;
}
for (ll i = b - 1; i <= n; i += b) {
ans = max(ans, (a * i) / b - a * (i / b));
}
cout << ans;
return 0;
}
int main() {
ios ll t = 1;
// cin>>t;
while (t--) {
solve();
}
} | /*
Coded and Decoded by : Yash Kapoor
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\n'
#define why (ll)1000000007
// #define why (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod) {
ll result = 1;
while (power) {
if (power % 2)
result = (result * base) % mod;
base = (base * base) % mod;
power /= 2;
}
return result;
}
ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }
ll solve() {
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
if (b - 1 > n or b == 1) {
cout << (a * n) / b - a * (n / b);
return 0;
}
for (ll i = b - 1; i <= n; i += b) {
ans = max(ans, (a * i) / b - a * (i / b));
}
cout << ans;
return 0;
}
int main() {
ios ll t = 1;
// cin>>t;
while (t--) {
solve();
}
} | replace | 53 | 54 | 53 | 54 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) \
rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main() {
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
rp(i, 0, min(n, b) + 1) { ans = max(ans, ll(a * i / b) - a * ll(i / b)); }
ce(ans);
} | #include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) \
rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main() {
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
if (n >= b - 1) {
ce(ll(a * (b - 1) / b) - a * ll((b - 1) / b));
} else {
ce(ll(a * (n) / b) - a * ll((n) / b));
}
} | replace | 16 | 18 | 16 | 21 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
using namespace std;
typedef long long ll;
ll A, B, N;
int main() {
cin >> A >> B >> N;
ll ans = 0;
rep(i, max(N + 1, (ll)1000000)) {
ans = max(ans, (A * (N - i)) / B - A * ((N - i) / B));
}
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
using namespace std;
typedef long long ll;
ll A, B, N;
int main() {
cin >> A >> B >> N;
ll ans = A * min(N, B - 1) / B;
cout << ans << endl;
} | replace | 21 | 25 | 21 | 22 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long ans;
int main() {
cin >> a >> b >> n;
if (n < b) {
cout << max(ans, a * n / b - a * (n / b));
} else {
for (int i = b - 1; i <= min(n, a * b); i += b) {
ans = max(ans, a * i / b - a * (i / b));
}
cout << ans;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long ans;
int main() {
cin >> a >> b >> n;
if (n < b) {
cout << max(ans, a * n / b - a * (n / b));
} else {
if (a * b > n) {
for (long long i = b - 1; i <= n; i += b) {
long long tot = a * i / b - a * (i / b);
if (tot > ans) {
ans = tot;
}
}
} else {
for (long long i = 1; i <= a; i++) {
long long tot = a * (i * b - 1) / b - a * (i - 1);
if (tot > ans) {
ans = tot;
}
}
}
cout << ans;
}
return 0;
}
| replace | 9 | 11 | 9 | 23 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, N;
cin >> A >> B >> N;
long long counter = 0;
counter = ((A * N) / B) - A * (N / B);
long long i = N;
for (i; i > 0; i--) {
if (i % B == 0) {
i--;
break;
} else
continue;
}
counter = max(counter, ((A * i) / B) - A * (i / B));
cout << counter << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, N;
cin >> A >> B >> N;
long long counter = 0;
counter = ((A * N) / B) - A * (N / B);
long long i = N - (N % B) - 1;
counter = max(counter, ((A * i) / B) - A * (i / B));
cout << counter << endl;
return 0;
}
| replace | 7 | 15 | 7 | 8 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset> // bitset
#include <cmath> // sqrt
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;
int main() {
ll A, B, N;
cin >> A >> B >> N;
ll ans = 0;
ll x = N;
for (ll x = N % B; x < N + 1; x++) {
long double a = A * x / B;
ll aa = a;
long double b = x / B;
ll bb = b * A;
ans = max(ans, aa - bb);
// cout << ans << endl;
}
cout << ans << endl;
return 0;
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset> // bitset
#include <cmath> // sqrt
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;
int main() {
ll A, B, N;
cin >> A >> B >> N;
ll ans = 0;
ll x = min(B - 1, N);
ll tmp = floor(A * x / B) - A * floor(x / B);
ans = max(ans, tmp);
cout << ans << endl;
return 0;
}
| replace | 31 | 40 | 31 | 36 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, N, X = 0, T;
cin >> A >> B >> N;
for (long long I = 0; I <= N; I++) {
T = floor((A * I) / B) - (A * floor(I / B));
X = max(X, T);
}
cout << X << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int a;
long long b, n;
cin >> a >> b >> n;
long long mn = min(n, b - 1);
cout << a * mn / b << '\n';
return 0;
}
| replace | 4 | 14 | 4 | 12 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
long long int A, B, N, i, j, ans = 0;
cin >> A >> B >> N;
if (N >= B - 1) {
for (i = B - 1; i <= N; i += B)
ans = (ans, A * i / B - A * (i / B));
} else
ans = (A * N / B - A * (N / B));
cout << ans << '\n';
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
long long int A, B, N, i, j, ans = 0;
cin >> A >> B >> N;
ans = (N >= B - 1) ? A * (B - 1) / B - A * ((B - 1) / B)
: (A * N / B - A * (N / B));
cout << ans << '\n';
return 0;
}
| replace | 10 | 15 | 10 | 12 | TLE | |
p02696 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) \
{ std::cout << #a << " = " << a << "\n"; }
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
return a < b && (a = b, 1);
}
template <class T, class V> istream &operator>>(istream &ist, pair<T, V> &p) {
return ist >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &ost, pair<T, T> &p) {
return ost << p.first << ", " << p.second;
}
template <class T> istream &operator>>(istream &ist, vector<T> &vs) {
for (auto &e : vs)
ist >> e;
return ist;
}
typedef long long ll;
int const inf = INT_MAX / 2;
ll f(ll A, ll B, ll x) { return A * x / B - A * (x / B); }
int main() {
ll A, B, N;
cin >> A >> B >> N;
cout << f(A, B - 1, N) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) \
{ std::cout << #a << " = " << a << "\n"; }
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
return a < b && (a = b, 1);
}
template <class T, class V> istream &operator>>(istream &ist, pair<T, V> &p) {
return ist >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &ost, pair<T, T> &p) {
return ost << p.first << ", " << p.second;
}
template <class T> istream &operator>>(istream &ist, vector<T> &vs) {
for (auto &e : vs)
ist >> e;
return ist;
}
typedef long long ll;
int const inf = INT_MAX / 2;
ll f(ll A, ll B, ll x) { return A * x / B - A * (x / B); }
int main() {
ll A, B, N;
cin >> A >> B >> N;
cout << f(A, B, min(B - 1, N)) << "\n";
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef std::pair<int, int> pii;
using namespace std;
ll temp(ll a, ll b, ll x) {
ll axb = (long double)(a * x) / (long double)b;
ll bx = (long double)x / (long double)b;
// cout << axb << " " << a * bx << endl;
return axb - a * bx;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
ll x = n;
for (ll i = n; i >= 0; i--) {
ans = max(temp(a, b, i), ans);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef std::pair<int, int> pii;
using namespace std;
ll temp(ll a, ll b, ll x) {
ll axb = (long double)(a * x) / (long double)b;
ll bx = (long double)x / (long double)b;
// cout << axb << " " << a * bx << endl;
return axb - a * bx;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a, b, n;
cin >> a >> b >> n;
ll x = n > b - 1 ? b - 1 : n;
ll ans = temp(a, b, x);
cout << ans << endl;
return 0;
}
| replace | 27 | 32 | 27 | 29 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll a, b, n;
int main(void) {
scanf("%lld%lld%lld", &a, &b, &n);
ll ans = a * (n) / b - a * ((n) / b);
for (ll i = b - 1; i <= n; i += b) {
ans = max(ans, a * i / b - a * (i / b));
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll a, b, n;
int main(void) {
scanf("%lld%lld%lld", &a, &b, &n);
ll ans = a * (n) / b - a * ((n) / b);
for (ll i = b - 1; i <= min(n, a * b); i += b) {
ans = max(ans, a * i / b - a * (i / b));
}
printf("%lld\n", ans);
return 0;
}
| replace | 11 | 12 | 11 | 12 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void) {
ll A, B, N, b;
cin >> A >> B >> N;
if (B > N)
b = N;
else
b = B - 1;
ll max_x = 0;
for (ll i = 0; i < B; i++)
max_x = max(max_x, A * (b - i) / B - A * ((b - i) / B));
cout << max_x << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void) {
ll A, B, N, b;
cin >> A >> B >> N;
if (B > N)
b = N;
else
b = B - 1;
ll max_x = 0;
for (ll i = 0; i < 100000; i++)
max_x = max(max_x, A * (b - i) / B - A * ((b - i) / B));
cout << max_x << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>>
spqint; // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll; // 小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint; // 大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll; // 大きい順に取り出し
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最小公倍数
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
//-----------------------------------------
//-----------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
for (ll i = 0; i <= sqrt(n); i++) {
ll j = n - i;
ll k = floor(a * j / b) - a * floor(j / b);
ans = max(ans, k);
}
for (ll i = 0; i <= sqrt(n); i++) {
ll l = floor(a * i / b) - a * floor(i / b);
ans = max(ans, l);
}
ll bb = b;
while (1) {
if (bb >= n) {
break;
}
ll m = floor(a * (bb - 1) / b) - a * floor((bb - 1) / b);
ans = max(m, ans);
bb += b;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>>
spqint; // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll; // 小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint; // 大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll; // 大きい順に取り出し
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最小公倍数
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
//-----------------------------------------
//-----------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
if (b > n) {
ans = (a * n) / b - a * (n / b);
} else {
ans = (a * (b - 1)) / b;
}
cout << ans << endl;
return 0;
}
| replace | 58 | 75 | 58 | 62 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int binary(int bina) {
int ans = 0;
for (int i = 0; bina > 0; i++) {
ans = ans + (bina % 2) * pow(10, i);
bina = bina / 2;
}
return ans;
}
long comb(int n, int r) {
long ans = 1;
for (int i = n; i > n - r; --i) {
ans = ans * i;
}
for (int i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
using namespace std;
/*int main(){
int n;std::cin >> n;
int keta=0;
while(true){
keta++;
if(n/10==0)break;
n=n/10;
}
keta=keta-1;
if(n>=7)n=3;
else if(n>=5)n=2;
else if(n>=3)n=1;
int k=0;
for(int i=3;i<=keta;i++){
k+=comb(i-1,2);
std::cout << k << std::endl;
}std::cout << k << std::endl;
k+=n*(keta);
std::cout << k << std::endl;
}
*/
int main() {
unsigned long long a, b, n;
int s = 0;
std::cin >> a >> b >> n;
int w;
for (int i = 1; i < n + 1; i++) {
w = (((a * i) / b) - a * (i / b));
s = max(s, w);
}
std::cout << s << std::endl;
return 0;
}
| #include <algorithm>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int binary(int bina) {
int ans = 0;
for (int i = 0; bina > 0; i++) {
ans = ans + (bina % 2) * pow(10, i);
bina = bina / 2;
}
return ans;
}
long comb(int n, int r) {
long ans = 1;
for (int i = n; i > n - r; --i) {
ans = ans * i;
}
for (int i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
using namespace std;
/*int main(){
int n;std::cin >> n;
int keta=0;
while(true){
keta++;
if(n/10==0)break;
n=n/10;
}
keta=keta-1;
if(n>=7)n=3;
else if(n>=5)n=2;
else if(n>=3)n=1;
int k=0;
for(int i=3;i<=keta;i++){
k+=comb(i-1,2);
std::cout << k << std::endl;
}std::cout << k << std::endl;
k+=n*(keta);
std::cout << k << std::endl;
}
*/
int main() {
unsigned long long a, b, n;
int s = 0;
std::cin >> a >> b >> n;
std::cout << a * min((b - 1), n) / b << std::endl;
return 0;
}
| replace | 65 | 71 | 65 | 67 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll a, b, n;
cin >> a >> b >> n;
ll ans = 0;
for (ll i = 1; i <= min(b, n); i++) {
ll buf = floor(a * i / b) - a * floor(i / b);
ans = max(ans, buf);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll a, b, n;
cin >> a >> b >> n;
ll s = min(b - 1, n);
ll ans = floor(a * s / b) - a * floor(s / b);
cout << ans << endl;
}
| replace | 7 | 12 | 7 | 10 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
int main() {
int A;
long long B, N;
long long ans;
std::cin >> A >> B >> N;
ans = (A * N) / B - (N / B) * A;
for (long long x = B - 1; x <= N; x += B) {
long long buf = (A * x) / B - (x / B) * A;
if (ans < buf) {
ans = buf;
}
}
std::cout << ans;
} | #include <cmath>
#include <iostream>
int main() {
int A;
long long B, N;
long long ans;
std::cin >> A >> B >> N;
ans = (A * N) / B - (N / B) * A;
// for(long long x=B-1;x<=N;x+=B){
// long long buf=(A*x)/B-(x/B)*A;
// if(ans<buf){
// ans=buf;
// }
// }
long long buf = ((N / B) - 1) * B + B - 1;
buf = (A * buf) / B - (buf / B) * A;
if (ans < buf) {
ans = buf;
}
std::cout << ans;
} | replace | 9 | 14 | 9 | 19 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t A, B, N;
cin >> A >> B >> N;
// vector<vector<int>> input(q, vector<int>(4));
int64_t loop = N / B + 1;
int64_t x, ans, tmp;
ans = 0;
for (int i = 1; i <= loop; i++) {
if ((i * B - 1) < N)
x = i * B - 1;
else
x = N;
tmp = floor(A * x / B) - A * floor(x / B);
if (tmp > ans)
ans = tmp;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t A, B, N;
cin >> A >> B >> N;
// vector<vector<int>> input(q, vector<int>(4));
int64_t loop = N / B + 1;
int64_t x, ans, tmp;
ans = 0;
if (B == 1) {
ans = 0;
} else {
for (int i = 1; i <= loop; i++) {
if ((i * B - 1) < N)
x = i * B - 1;
else
x = N;
tmp = floor(A * x / B) - A * floor(x / B);
if (tmp > ans)
ans = tmp;
}
}
cout << ans << endl;
}
| replace | 13 | 21 | 13 | 25 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
// constant
//--------------------------------------------
const double PI = acos(-1.0);
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
const LL MOD = 1e9 + 7;
// vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
if(x == 0) return 0;
return counter_1(x >> 1) + (x & 1);
}*/
// int Counter(int x)
/*int factorial(int n) {
if (n > 0) {
return n * factorial(n - 1);
} else {
return 1;
}
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
return firstElof.second > secondElof.second;
}*/
/*long nCr(int n, int r)
{
if(n==r) return dp[n][r] = 1;
if(r==0) return dp[n][r] = 1;
if(r==1) return dp[n][r] = n;
if(dp[n][r]) return dp[n][r];
return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}*/
/*int stoi(std::string str){
int ret;
std::stringstream ss;
ss << str;
ss >> ret;
return ret;
}*/
void Main() {
LL n, a, b;
cin >> a >> b >> n;
LL ans = 0;
LL x = min(b - 1, n);
double af = 0.0;
FOR(i, 1, x + 1) {
double f = i / (double)b;
LL z = i / b;
// cout << f << endl;
af = max(f - double(z), af);
}
ans = (a * af) / 1;
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(0);
Main();
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
// constant
//--------------------------------------------
const double PI = acos(-1.0);
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
const LL MOD = 1e9 + 7;
// vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
if(x == 0) return 0;
return counter_1(x >> 1) + (x & 1);
}*/
// int Counter(int x)
/*int factorial(int n) {
if (n > 0) {
return n * factorial(n - 1);
} else {
return 1;
}
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
return firstElof.second > secondElof.second;
}*/
/*long nCr(int n, int r)
{
if(n==r) return dp[n][r] = 1;
if(r==0) return dp[n][r] = 1;
if(r==1) return dp[n][r] = n;
if(dp[n][r]) return dp[n][r];
return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}*/
/*int stoi(std::string str){
int ret;
std::stringstream ss;
ss << str;
ss >> ret;
return ret;
}*/
void Main() {
LL n, a, b;
cin >> a >> b >> n;
LL ans = 0;
LL x = min(b - 1, n);
double af = 0.0;
double f = x / (double)b;
LL z = x / b;
// cout << f << endl;
af = f - double(z);
ans = (a * af) / 1;
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(0);
Main();
}
| replace | 124 | 130 | 124 | 128 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(), v.end()
#define mem(v, x) memset(v, x, sizeof(v))
#define N 100005
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll a, b, n;
cin >> a >> b >> n;
ll val = 0;
ll temp = b - 1;
while (1) {
if (temp > n)
break;
ll nval = a * temp / b - (temp / b) * a;
if (nval < val)
break;
val = max(val, nval);
temp += b;
}
ll nval = a * n / b - (n / b) * a;
val = max(val, nval);
cout << val;
}
| #include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(), v.end()
#define mem(v, x) memset(v, x, sizeof(v))
#define N 100005
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll a, b, n;
cin >> a >> b >> n;
ll val = 0;
if (n >= b - 1)
val = a * (b - 1) / b;
ll nval = a * n / b - (n / b) * a;
val = max(val, nval);
cout << val;
}
| replace | 22 | 32 | 22 | 24 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
using pii = pair<int, int>;
using piii = pair<pii, int>;
using pll = pair<long long, long long>;
using plll = pair<pll, long long>;
// #pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define isSquare(x) (sqrt(x) * sqrt(x) == x)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
};
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
};
inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
cin >> first;
in(rest...);
return;
}
inline void out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void out(First first, Rest... rest) {
cout << first << " ";
out(rest...);
return;
}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long INFLL = 1e18;
void iosetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
pair<S, T> operator*(const pair<S, T> &s, const S &t) {
return pair<S, T>(s.first * t, s.second * t);
}
template <typename T> void Exit(T first) {
cout << first << endl;
exit(0);
};
template <int mod> struct ModInt {
unsigned x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<mod>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const pii dxy[4] = {pii(1, 0), pii(0, 1), pii(-1, 0), pii(0, -1)};
const int calender[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int ucalender[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool range(int a, int b, int x) {
if (a <= x and x < b)
return true;
else
return false;
}
bool range(int a, int b, int c, int d, pii p) {
if (a <= p.first and p.first < b and c <= p.second and p.second < d)
return true;
else
return false;
}
int main() {
iosetup();
ll A, B, N;
cin >> A >> B >> N;
ll ans = 0;
for (ll i = N; i >= sqrt(N); i--) {
chmax(ans, (ll)A * i / B - A * (i / B));
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
using pii = pair<int, int>;
using piii = pair<pii, int>;
using pll = pair<long long, long long>;
using plll = pair<pll, long long>;
// #pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define isSquare(x) (sqrt(x) * sqrt(x) == x)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
};
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
};
inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
cin >> first;
in(rest...);
return;
}
inline void out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void out(First first, Rest... rest) {
cout << first << " ";
out(rest...);
return;
}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long INFLL = 1e18;
void iosetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
pair<S, T> operator*(const pair<S, T> &s, const S &t) {
return pair<S, T>(s.first * t, s.second * t);
}
template <typename T> void Exit(T first) {
cout << first << endl;
exit(0);
};
template <int mod> struct ModInt {
unsigned x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<mod>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const pii dxy[4] = {pii(1, 0), pii(0, 1), pii(-1, 0), pii(0, -1)};
const int calender[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int ucalender[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool range(int a, int b, int x) {
if (a <= x and x < b)
return true;
else
return false;
}
bool range(int a, int b, int c, int d, pii p) {
if (a <= p.first and p.first < b and c <= p.second and p.second < d)
return true;
else
return false;
}
int main() {
iosetup();
ll A, B, N;
cin >> A >> B >> N;
ll ans = 0;
ll k = N / B;
ll x = k * B;
ans = (ll)A * (x - 1) / B - A * ((x - 1) / B);
chmax(ans, (ll)A * N / B - A * (N / B));
cout << ans << endl;
return 0;
} | replace | 199 | 202 | 199 | 203 | TLE | |
p02696 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
// 最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
// 出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
// 最大公約数
unsigned gcd(unsigned a, unsigned b) {
if (a < b)
return gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
int main() {
ll a, b, n;
cin >> a >> b >> n;
if (b - 1 > n) {
cout << (a * n) / b - a * (n / b) << endl;
return 0;
}
ll x = (a * (b - 1)) / b - a * ((b - 1) / b);
ll pos = (n - (n % (b - 1)));
ll y = (a * pos) / b - a * (pos / b);
x > y ? print(x) : print(y);
} | #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
// 最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
// 出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
// 最大公約数
unsigned gcd(unsigned a, unsigned b) {
if (a < b)
return gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
int main() {
ll a, b, n;
cin >> a >> b >> n;
if (b - 1 > n) {
cout << (a * n) / b - a * (n / b) << endl;
return 0;
}
if (b == 1) {
cout << 0 << endl;
return 0;
}
ll x = (a * (b - 1)) / b - a * ((b - 1) / b);
ll pos = (n - (n % (b - 1)));
ll y = (a * pos) / b - a * (pos / b);
x > y ? print(x) : print(y);
} | insert | 243 | 243 | 243 | 247 | 0 | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main(void) {
long long a, b, n;
cin >> a >> b >> n;
long long x = n, res = 0, lim = b / a;
while (x > lim)
res = max(res, a * x / b - a * (x / b)), --x;
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
long long a, b, n;
cin >> a >> b >> n;
long long res;
if (n / b == 0)
res = a * n / b - a * (n / b);
else
res = a * (n / b * b - 1) / b - a * ((n / b * b - 1) / b);
cout << res << endl;
return 0;
}
| replace | 6 | 9 | 6 | 11 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int A, B, N;
cin >> A >> B >> N;
long long int x = min(B - 1, N);
long long int ans = 0;
while (true) {
long long int tmp_ans = A * x / B - x / B * A;
if (tmp_ans > ans) {
ans = tmp_ans;
}
if (x == N) {
break;
}
x = min(x + B, N);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int A, B, N;
cin >> A >> B >> N;
long long int x = min(B - 1, N);
long long int ans = A * x / B - x / B * A;
cout << ans << endl;
} | replace | 9 | 21 | 9 | 10 | TLE | |
p02696 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int64_t a, b, n;
cin >> a >> b >> n;
int64_t ans1 = a * n / b - a * (n / b);
int64_t ans2 = 0;
int x = b - 1;
if (n >= b - 1)
ans2 = a / (b - 1);
cout << max(ans1, ans2) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int64_t a, b, n;
cin >> a >> b >> n;
int64_t ans1 = a * n / b - a * (n / b);
int64_t ans2 = 0;
if (b != 1) {
if (n >= b - 1)
ans2 = a * (b - 1) / b;
}
cout << max(ans1, ans2) << endl;
} | replace | 9 | 12 | 9 | 13 | 0 | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int64_t sol(int64_t a, int64_t b, int64_t n) {
int64_t before = -1, cur = 0, i = 1;
for (i = 1; i <= min((int64_t)5e8, n); ++i) {
cur = floor((double)a * i / b) - a * floor((double)i / b);
if (before > cur) {
break;
}
before = cur;
}
return before;
}
int main() {
int64_t a, b, n;
cin >> a >> b >> n;
cout << sol(a, b, n);
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int64_t sol(int64_t a, int64_t b, int64_t n) {
int64_t i = min(n, b - 1);
return floor((double)a * i / b) - a * floor((double)i / b);
}
int main() {
int64_t a, b, n;
cin >> a >> b >> n;
cout << sol(a, b, n);
return 0;
} | replace | 6 | 15 | 6 | 8 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<pii, int>;
int main() {
ll a, b, n;
cin >> a >> b >> n;
int ans = -2e9;
int r = n - b;
for (ll i = max(1, r); i <= n; i++) {
int x = (a * i) / b;
int y = (i / b);
int m = x - a * y;
ans = max(ans, m);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<pii, int>;
int main() {
ll a, b, n;
cin >> a >> b >> n;
ll s = b - 1;
int ans;
bool ok = true;
while (ok) {
if (s <= n) {
int x = (a * s) / b;
int y = (s / b);
ans = x - a * y;
ok = false;
} else
s--;
}
cout << ans << endl;
} | replace | 10 | 17 | 10 | 21 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n, k) for (int i = (n); i < (k); i++)
#define ALL(a) (a).begin(), (a).end()
ll ans = 0;
ll calc(ll a, ll b, ll x) { return a * x / b - x / b * a; }
void Main() {
ll a;
cin >> a;
ll b;
cin >> b;
ll n;
cin >> n;
for (ll i = 1; i < n + 1; i++) {
ll t = calc(a, b, i);
if (t > ans)
ans = t;
else if (t < ans)
break;
}
cout << ans << endl;
}
int main() {
Main();
/*
東方風神録は神が出てくるので当然神ゲー
*/
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n, k) for (int i = (n); i < (k); i++)
#define ALL(a) (a).begin(), (a).end()
ll ans = 0;
ll calc(ll a, ll b, ll x) { return a * x / b - x / b * a; }
void Main() {
ll a;
cin >> a;
ll b;
cin >> b;
ll n;
cin >> n;
for (ll i = min(b, n); i > 0; i--) {
ll t = calc(a, b, i);
if (t > ans)
ans = t;
else if (t < ans)
break;
}
cout << ans << endl;
}
int main() {
Main();
/*
東方風神録は神が出てくるので当然神ゲー
*/
return 0;
} | replace | 14 | 15 | 14 | 15 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll m, ll n) {
if ((0 == m) || (0 == n))
return 0;
return ((m / gcd(m, n)) * n);
}
ll llpow(ll x, ll y) {
ll ans = 1;
REP(i, y)
ans *= x;
return ans;
}
ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }
template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v) {
return (c.end() != std::find(c.begin(), c.end(), v));
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll nCr(int n, int r) {
if (n == r or n == 0)
return 1;
if (n < r)
return 0;
if (r == 1)
return n;
return nCr(n - 1, r - 1) + nCr(n - 1, r);
}
// std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
ll A, B, N;
cin >> A >> B >> N;
ll cnt = 0, res = 0;
FOR(i, 1, llmin(B, N) + 1) {
ll hold = floor(A * i / B) - A * floor(i / B);
if (hold > res)
res = hold;
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll m, ll n) {
if ((0 == m) || (0 == n))
return 0;
return ((m / gcd(m, n)) * n);
}
ll llpow(ll x, ll y) {
ll ans = 1;
REP(i, y)
ans *= x;
return ans;
}
ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }
template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v) {
return (c.end() != std::find(c.begin(), c.end(), v));
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll nCr(int n, int r) {
if (n == r or n == 0)
return 1;
if (n < r)
return 0;
if (r == 1)
return n;
return nCr(n - 1, r - 1) + nCr(n - 1, r);
}
// std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
ll A, B, N;
cin >> A >> B >> N;
ll cnt = 0, res = 0;
FOR(j, 1, llmin(B, N) + 1) {
ll times = (B > N) ? llmin(B, N) : llmin(B, N) - 1;
if (times * j > N)
break;
ll hold = floor(A * times * j / B) - A * floor(times * j / B);
if (hold > res)
res = hold;
}
cout << res << endl;
return 0;
}
| replace | 70 | 72 | 70 | 75 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-12)
#define pb push_back
long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N / i != i)
res.push_back(N / i);
}
}
sort(res.begin(), res.end());
return res;
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
struct edge {
ll to, cost;
};
typedef long double ld;
using Graph = vector<VE>;
class UnionFind {
public:
vector<ll> par; // 各元の親を表す配列
vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
void init(ll sz_) {
par.resize(sz_);
siz.resize(sz_, 1);
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
// Member Function
// Find
ll root(ll x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(20);
// combination com(200010);
int a, b;
cin >> a >> b;
int n;
cin >> n;
int before = -INF;
rep(i, n + 1) {
int now = (a * i) / b - a * (i / b);
if (before > now) {
cout << before << endl;
return 0;
}
before = now;
}
cout << before << endl;
/*
ld l = 0, r = n;
rep(i, 10010) {
ld t1 = (2 * l + r) / 3;
ld t2 = (l + 2 * r) / 3;
ld tmp = ((ld)a * t1 / (ld)b) - ((ld)a *(t1 / (ld)b));
ld tmp2 = ((ld)a * t2 / (ld)b) - ((ld)a *(t2 / (ld)b));
if (tmp > tmp2)r = t2;
else l = t1;
}
rep(i, n + 1) {
cout << (a * i / b) - (a *(i / b)) << endl;
}
int now = l;int now2 = (l + 1);
int ans = (a * now / b) - (a *(now / b));
if (now2 <= n)chmax(ans, (int)((a * now2 / b) - (a *(now2 / b))));
cout << ans << endl;*/
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-12)
#define pb push_back
long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N / i != i)
res.push_back(N / i);
}
}
sort(res.begin(), res.end());
return res;
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
struct edge {
ll to, cost;
};
typedef long double ld;
using Graph = vector<VE>;
class UnionFind {
public:
vector<ll> par; // 各元の親を表す配列
vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
void init(ll sz_) {
par.resize(sz_);
siz.resize(sz_, 1);
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
// Member Function
// Find
ll root(ll x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(20);
// combination com(200010);
int a, b, n;
cin >> a >> b >> n;
if (b - 1 <= n)
n = b - 1;
cout << (a * n) / b - a * (n / b) << endl;
return 0;
}
| replace | 314 | 345 | 314 | 319 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll A, B, N;
cin >> A >> B >> N;
ll res = 0;
for (ll x = N; x - B <= x && 0 <= x; x--) {
res = max(res, (ll)(floor((A * x) / B) - A * floor(x / B)));
}
cout << res;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll A, B, N;
cin >> A >> B >> N;
ll x = min(N, B - 1);
cout << (ll)(floor(A * x / B) - A * floor(x / B)) << endl;
} | replace | 7 | 12 | 7 | 9 | TLE | |
p02696 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const ll INF = 2e18;
const int inf = 1e9 + 10;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100;
const int MOD = 1000000007;
ll x, y, n;
int main() {
freopen("a.txt", "r", stdin);
freopen("b.txt", "w", stdout);
scanf("%lld%lld%lld", &x, &y, &n);
ll t = min(y - 1, n);
ll ans = (x * t) / y - x * (t / y);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const ll INF = 2e18;
const int inf = 1e9 + 10;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100;
const int MOD = 1000000007;
ll x, y, n;
int main() {
scanf("%lld%lld%lld", &x, &y, &n);
ll t = min(y - 1, n);
ll ans = (x * t) / y - x * (t / y);
cout << ans << endl;
return 0;
} | delete | 17 | 19 | 17 | 17 | -8 | |
p02696 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, N;
cin >> A >> B >> N;
long long ans = 0;
for (int i = 0; i <= N; i++) {
long long temp = 0;
temp = A * i / B - A * (i / B);
if (temp >= ans) {
ans = temp;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, N;
cin >> A >> B >> N;
long long z = min(B - 1, N);
long long ans = A * z / B;
cout << ans << endl;
return 0;
} | replace | 7 | 15 | 7 | 9 | TLE | |
p02696 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
long long a, b, n;
cin >> a >> b >> n;
long long f = 0;
if (n < b)
f = (a * n) / b - a * (n / b);
if (n == b)
f = (a * (n - 1)) / b - a * ((n - 1) / b);
if (n > b)
for (long long i = 0; i <= n % b; i++) {
long long t = (a * (n - i)) / b - a * ((n - i) / b);
if (t > f)
f = t;
}
cout << f << endl;
} | #include <iostream>
using namespace std;
int main() {
long long a, b, n;
cin >> a >> b >> n;
long long f = 0;
if (n < b)
f = (a * n) / b - a * (n / b);
if (n == b)
f = (a * (n - 1)) / b - a * ((n - 1) / b);
if (n > b)
f = (a * (n - 1 - n % b)) / b - a * ((n - 1 - n % b) / b);
cout << f << endl;
} | replace | 11 | 16 | 11 | 13 | TLE | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
if (n % 2)
cout << i << " " << n - i + 1 << endl;
else
exit(9);
}
return (0);
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, m;
cin >> n >> m;
n -= (n % 2 == 0);
int start = 1;
int end = n / 2;
int cnt = 0;
while (1) {
if (start >= end - start + 1 || cnt == m)
break;
cout << start << " " << end - start + 1 << endl;
start++;
cnt++;
}
start = n / 2 + 1;
end = n;
while (1) {
if (start >= end - start + (n / 2 + 1) || cnt == m)
break;
cout << start << " " << end - start + (n / 2 + 1) << endl;
start++;
cnt++;
}
return (0);
}
| replace | 6 | 11 | 6 | 25 | 9 | |
p02697 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using int64 = long long;
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<pair<int, int>> ams;
if (N % 2 == 1) {
for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
ams.emplace_back(lb, ub);
}
} else {
bool flag = false;
for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
if (!flag && ub - lb <= N / 2) {
flag = false;
ub--;
}
ams.emplace_back(lb, ub);
}
}
for (int i = 0; i < M; i++) {
cout << ams[i].first << " " << ams[i].second << endl;
}
return 0;
}
| #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using int64 = long long;
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<pair<int, int>> ams;
if (N % 2 == 1) {
for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
ams.emplace_back(lb, ub);
}
} else {
bool flag = false;
for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
if (!flag && ub - lb <= N / 2) {
flag = true;
ub--;
}
ams.emplace_back(lb, ub);
}
}
for (int i = 0; i < M; i++) {
cout << ams[i].first << " " << ams[i].second << endl;
}
return 0;
}
| replace | 43 | 44 | 43 | 44 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;
#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class S> inline bool chmax(T &a, S b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> void line(vector<T> &x) {
for (auto &&xi : x)
cin >> xi;
}
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
cin >> first;
IN(rest...);
return;
}
#define INT(...) \
int __VA_ARGS__; \
IN(__VA_ARGS__)
#define LINT(...) \
lint __VA_ARGS__; \
IN(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
IN(__VA_ARGS__)
template <class T> void UNIQUE(vector<T> &x) {
sort(all(x));
x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end) {
for (auto i = first; i < end - 1; i++)
cout << *i << " ";
cout << *(end - 1) << endl;
}
template <class... T> void debug_print(T... args) {
vector<lint> tmp = initializer_list<lint>{args...};
print_vec(all(tmp));
}
template <class T> void print(T a) { cout << a << endl; }
vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};
int ord(char x) { return (int)(x - 'a'); }
char chr(lint x) { return (char)(x + (lint)('a')); }
lint mod = 1e9 + 7;
// lint mod =
lint sum(vlint a) {
lint ret = 0;
for (auto &&v : a)
ret += v;
return ret;
}
lint vmini(vlint a, lint &index) {
lint ret = LLONG_MAX;
rep(i, Size(a)) {
if (chmin(ret, a[i]))
index = i;
}
return ret;
}
lint vmaxi(vlint a, lint &index) {
lint ret = -LLONG_MAX;
rep(i, Size(a)) {
if (chmax(ret, a[i]))
index = i;
}
return ret;
}
lint vmin(vlint a) {
lint ret = LLONG_MAX;
for (auto &&v : a)
chmin(ret, v);
return ret;
}
lint vmax(vlint a) {
lint ret = -LLONG_MAX;
for (auto &&v : a)
chmax(ret, v);
return ret;
}
int main() {
INT(n, m);
vector<vlint> ans;
vlint check(n + 1, 0);
check[0] = 1;
int left = 1, right = n;
while (Size(ans) < m) {
if (check[right - left]) {
left++;
continue;
}
ans.pb({left, right});
left++;
right--;
check[right - left] = 1;
check[n - right + left] = 1;
}
rep(i, m) { print_vec(all(ans[i])); }
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;
#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class S> inline bool chmax(T &a, S b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> void line(vector<T> &x) {
for (auto &&xi : x)
cin >> xi;
}
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
cin >> first;
IN(rest...);
return;
}
#define INT(...) \
int __VA_ARGS__; \
IN(__VA_ARGS__)
#define LINT(...) \
lint __VA_ARGS__; \
IN(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
IN(__VA_ARGS__)
template <class T> void UNIQUE(vector<T> &x) {
sort(all(x));
x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end) {
for (auto i = first; i < end - 1; i++)
cout << *i << " ";
cout << *(end - 1) << endl;
}
template <class... T> void debug_print(T... args) {
vector<lint> tmp = initializer_list<lint>{args...};
print_vec(all(tmp));
}
template <class T> void print(T a) { cout << a << endl; }
vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};
int ord(char x) { return (int)(x - 'a'); }
char chr(lint x) { return (char)(x + (lint)('a')); }
lint mod = 1e9 + 7;
// lint mod =
lint sum(vlint a) {
lint ret = 0;
for (auto &&v : a)
ret += v;
return ret;
}
lint vmini(vlint a, lint &index) {
lint ret = LLONG_MAX;
rep(i, Size(a)) {
if (chmin(ret, a[i]))
index = i;
}
return ret;
}
lint vmaxi(vlint a, lint &index) {
lint ret = -LLONG_MAX;
rep(i, Size(a)) {
if (chmax(ret, a[i]))
index = i;
}
return ret;
}
lint vmin(vlint a) {
lint ret = LLONG_MAX;
for (auto &&v : a)
chmin(ret, v);
return ret;
}
lint vmax(vlint a) {
lint ret = -LLONG_MAX;
for (auto &&v : a)
chmax(ret, v);
return ret;
}
int main() {
INT(n, m);
vector<vlint> ans;
vlint check(n + 1, 0);
int cnt = 1;
int diff = n - 1;
while (cnt < cnt + diff) {
ans.pb({cnt, cnt + diff});
cnt++;
diff -= 2;
if (n % 2 == 0 && diff + 2 > n / 2 && diff <= n / 2)
diff--;
}
rep(i, m) { print_vec(all(ans[i])); }
}
| replace | 124 | 136 | 124 | 132 | 0 | |
p02697 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<P> ans;
if (n % 2) {
for (int l = 1, r = n - 1; l < r; l++, r--) {
ans.emplace_back(l, r);
}
} else {
bool flag = false;
for (int l = 1, r = n - 1; l < r; l++, r++) {
if (!flag && r - l <= n / 2) {
--r;
flag = true;
}
ans.emplace_back(l, r);
}
}
rep(i, m) { printf("%d %d\n", ans[i].first, ans[i].second); }
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<P> ans;
if (n % 2) {
for (int l = 1, r = n - 1; l < r; l++, r--) {
ans.emplace_back(l, r);
}
} else {
bool flag = false;
for (int l = 1, r = n - 1; l < r; l++, r--) {
if (!flag && r - l <= n / 2) {
--r;
flag = true;
}
ans.emplace_back(l, r);
}
}
rep(i, m) { printf("%d %d\n", ans[i].first, ans[i].second); }
return 0;
}
| replace | 16 | 17 | 16 | 17 | TLE | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define ld long double
#define showoff \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define f first
#define se second
#define maxn 200005
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vector<int>, greater<int>>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power(int a, int n) {
a %= mod;
if (n == 1)
return a;
if (n == 0)
return 1;
if (n % 2)
return (a * (power((a * a) % mod, n / 2) % mod)) % mod;
return power((a * a) % mod, n / 2) % mod;
}
const int inf = (int)1e18;
int inverse(int x) {
return power(x, mod - 2) % mod; // little fermat....
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> used(n + 5);
int i = 1, d = 1;
while (m > 0) {
while (used[i])
++i;
cout << i << " " << i + d << "\n";
used[i] = used[i + d] = 1;
d++;
m--;
}
}
signed main() {
showoff;
int T = 1;
// cin >> T;
FOR(t, 1, T + 1) { solve(); }
return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...
| #include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define ld long double
#define showoff \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define f first
#define se second
#define maxn 200005
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vector<int>, greater<int>>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power(int a, int n) {
a %= mod;
if (n == 1)
return a;
if (n == 0)
return 1;
if (n % 2)
return (a * (power((a * a) % mod, n / 2) % mod)) % mod;
return power((a * a) % mod, n / 2) % mod;
}
const int inf = (int)1e18;
int inverse(int x) {
return power(x, mod - 2) % mod; // little fermat....
}
void solve() {
int n, m;
cin >> n >> m;
int i = 1;
if (n % 2)
while (m > 0) {
cout << i << " " << n - i << "\n";
i++;
m--;
}
else {
set<int> diff;
int j = n;
while (m > 0) {
if (diff.find(j - i) == diff.end() && j - i != n / 2) {
diff.insert(j - i);
diff.insert(n - j + i);
cout << i << " " << j << "\n";
i++;
j--;
m--;
} else
j--;
}
}
}
signed main() {
showoff;
int T = 1;
// cin >> T;
FOR(t, 1, T + 1) { solve(); }
return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...
| replace | 45 | 54 | 45 | 66 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (N % 2)
for (int i = 0; i < M; i++)
cout << i + 1 << " " << N - i << endl;
else {
vector<bool> used(N + 1, false);
int pos = 1;
for (int k = M; k > 0; k--) {
while (1) {
if (!used[pos] && !used[pos + k]) {
cout << pos << " " << pos + k << endl;
used[pos] = used[pos + k] = true;
pos++;
break;
}
pos++;
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (N % 2)
for (int i = 0; i < M; i++)
cout << i + 1 << " " << N - i << endl;
else {
for (int i = 0; i < (M + 1) / 2; i++)
cout << i + 1 << " " << (M + 1) / 2 * 2 - i << endl;
int r = (M + 1) / 2 * 2;
for (int i = 0; i < M / 2; i++)
cout << r + i + 1 << " " << r + M / 2 * 2 + 1 - i << endl;
}
return 0;
} | replace | 10 | 23 | 10 | 15 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n % 2 == 1) {
for (int i = 0; i < m; i++) {
cout << i + 1 << " " << n - i << endl;
}
} else {
vector<bool> check(100005);
int arrow = 1;
int dif = 1;
int cnt = 0;
while (cnt < m) {
if (!check[arrow]) {
cout << arrow << " " << arrow + dif << endl;
check[arrow] = true;
check[arrow + dif] = true;
dif++;
cnt++;
}
arrow++;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n % 2 == 1) {
for (int i = 0; i < m; i++) {
cout << i + 1 << " " << n - i << endl;
}
} else {
for (int i = 0; i < m; i++) {
cout << i + 1 << " " << n - i - (2 * i >= m) << endl;
}
}
return 0;
} | replace | 11 | 24 | 11 | 13 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
int n, m;
cin >> n >> m;
ll p = (n - 1) / 2;
if (n % 2 != 0) {
rep(i, m) { cout << p - i << " " << p + i + 1 << endl; }
} else {
bool done[200010];
memset(done, 0, sizeof(done));
int now = 0;
int i = 0;
while (i < m) {
int diff = i + 1;
if (done[now] || done[(now + diff) % n]) {
now++;
continue;
} else
cout << now + 1 << " " << (now + diff) % n + 1 << endl;
done[now] = true;
done[now + diff] = true;
i++;
}
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
int n, m;
cin >> n >> m;
ll p = (n - 1) / 2;
if (n % 2 != 0) {
rep(i, m) { cout << p - i << " " << p + i + 1 << endl; }
return 0;
}
int h = n / 2;
rep(i, (m + 1) / 2) { cout << h / 2 - i << " " << h / 2 + i + 1 << endl; }
rep(i, m - (m + 1) / 2) {
cout << h + h / 2 - i - 1 << " " << h + h / 2 + i + 1 << endl;
}
return 0;
}
| replace | 20 | 36 | 20 | 29 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<bool> visited(N + 1, false);
int j = 1;
for (int i = 1; i <= M; ++i) {
while (visited[j])
++j;
cout << j << ' ' << j + i << endl;
visited[j] = visited[j + i] = true;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
bool even = (M % 2 == 0);
int left = 1;
int right = M;
if (!even)
++right;
while (left < right) {
cout << left << ' ' << right << endl;
++left;
--right;
}
left = M + 1;
if (!even)
++left;
right = left + M;
if (!even)
--right;
while (left < right) {
cout << left << ' ' << right << endl;
++left;
--right;
}
return 0;
} | replace | 9 | 16 | 9 | 31 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
int dat1[50005], dat2[50005];
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (!(n & 1))
n--;
int mm = (n - 1) / 2;
if (mm & 1) {
for (int i = 1; i <= mm / 2; i++) {
dat1[i] = i;
dat2[i] = (n + 1) / 2 - i;
}
for (int j = (n + 1) / 2, i = mm / 2 + 1, k = 0; i <= mm; i++, j++, k++) {
dat1[i] = j;
dat2[i] = n - k;
}
} else {
for (int i = 1; i <= mm / 2; i++) {
dat1[i] = i;
dat2[i] = (n + 3) / 2 - i;
}
for (int i = (n + 3) / 2, j = n, k = mm / 2 + 1; k <= mm; i++, j--, k++) {
dat1[k] = i;
dat2[k] = j;
}
}
// for(int i=1;i<=6;i++) cout<<dat1[i]<<" "<<dat2[i]<<endl;
for (int i = 1; i <= m; i++)
cout << dat1[i] << " " << dat2[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
int dat1[100005], dat2[100005];
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (!(n & 1))
n--;
int mm = (n - 1) / 2;
if (mm & 1) {
for (int i = 1; i <= mm / 2; i++) {
dat1[i] = i;
dat2[i] = (n + 1) / 2 - i;
}
for (int j = (n + 1) / 2, i = mm / 2 + 1, k = 0; i <= mm; i++, j++, k++) {
dat1[i] = j;
dat2[i] = n - k;
}
} else {
for (int i = 1; i <= mm / 2; i++) {
dat1[i] = i;
dat2[i] = (n + 3) / 2 - i;
}
for (int i = (n + 3) / 2, j = n, k = mm / 2 + 1; k <= mm; i++, j--, k++) {
dat1[k] = i;
dat2[k] = j;
}
}
// for(int i=1;i<=6;i++) cout<<dat1[i]<<" "<<dat2[i]<<endl;
for (int i = 1; i <= m; i++)
cout << dat1[i] << " " << dat2[i] << endl;
return 0;
}
| replace | 1 | 2 | 1 | 2 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<bool> used(n + 1);
for (int i = 1, j = 1; j <= m; i++, j++) {
while (used[i])
i++;
cout << i << ' ' << i + j << endl;
used[i] = used[i + j] = true;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
if (n & 1) {
for (int i = 0; i < m; i++) {
cout << i + 1 << ' ' << n - i << endl;
}
} else {
for (int i = 0; i < m; i++) {
if (i * 2 < (n - 2) / 2)
cout << i + 1 << ' ' << n - i << endl;
else
cout << i + 1 << ' ' << n - i - 1 << endl;
}
}
return 0;
}
| replace | 13 | 20 | 13 | 24 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
vector<int> b(m);
int c = (n + 1) / 2, d = 1, i = 0;
while (c - d > 0) {
a[i] = d;
b[i] = c;
++d;
--c;
++i;
}
int e = (n + 1) / 2 + 1, f = n;
while (f - e > 0) {
a[i] = e;
b[i] = f;
++e;
--f;
++i;
}
rep(i, m) { cout << a[i] << " " << b.at(i) << "\n"; }
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
vector<int> b(m);
if (m % 2 == 0) {
int c = m + 1, d = 1, i = 0;
while (c - d > 0) {
a[i] = d;
b[i] = c;
++d;
--c;
++i;
}
int e = m + 2, f = 2 * m + 1;
while (f - e > 0) {
a[i] = e;
b[i] = f;
++e;
--f;
++i;
}
} else {
int c = m, d = 1, i = 0;
while (c - d > 0) {
a[i] = d;
b[i] = c;
++d;
--c;
++i;
}
int e = m + 1, f = 2 * m + 1;
while (f - e > 0) {
a[i] = e;
b[i] = f;
++e;
--f;
++i;
}
}
rep(i, m) { cout << a[i] << " " << b.at(i) << "\n"; }
return 0;
} | replace | 11 | 26 | 11 | 45 | 0 | |
p02697 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
set<int> s;
for (int i = 1; i <= n; i++)
s.insert(i);
int i = 1;
while (i <= m) {
int front = *s.begin();
int next = front + i;
if (next > n) {
next -= n;
}
if (s.find(next) == s.end()) {
continue;
}
cout << front << ' ' << next << endl;
s.erase(front);
s.erase(next);
i++;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
int i = 0;
while (1) {
int start = 1 + i;
int end = m + 1 - i;
if (start >= end)
break;
cout << start << ' ' << end << endl;
i++;
}
i = 0;
while (1) {
int start = m + 2 + i;
int end = 2 * m + 1 - i;
if (start >= end)
break;
cout << start << ' ' << end << endl;
i++;
}
return 0;
}
| replace | 9 | 25 | 9 | 25 | TLE | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n) \
cerr << __LINE__ << ": " << #x << " = {"; \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << ((hoge) ? "," : "") << x[hoge]; \
cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
bool used[N];
fill(used, used + N, false);
int cur = 0;
for (int i = 1; i <= M; i++) {
while (cur < N && used[cur])
cur++;
used[cur] = true;
used[cur + i] = true;
cout << cur + 1 << " " << cur + i + 1 << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n) \
cerr << __LINE__ << ": " << #x << " = {"; \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << ((hoge) ? "," : "") << x[hoge]; \
cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
if (N & 1) {
for (int i = 1; i <= M; i++) {
cout << i << " " << N + 1 - i << endl;
}
} else {
for (int i = 1, len = M & 1 ? M : M - 1; len >= 1; i++, len -= 2) {
cout << i << " " << i + len << endl;
}
for (int i = N - 1, len = M & 1 ? M - 1 : M; len >= 2; i--, len -= 2) {
cout << i << " " << i - len << endl;
}
}
return 0;
}
| replace | 24 | 33 | 24 | 35 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int)v.size()
#define pr(v) \
For(i, 0, sz(v)) { cout << v[i] << " "; } \
cout << endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for (ll i = st; i < en; i++)
#define tr(x) for (auto it = x.begin(); it != x.end(); it++)
#define fast \
std::ios::sync_with_stdio(false); \
cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 200005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
int begtime = clock();
#define end_routine() \
cout << "\n\nTime elapsed: " << (clock() - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
bool vis[N];
void solve() {
int n, m;
cin >> n >> m;
assert(n <= 100000);
int si = 1;
int ei = n;
int i = 0;
vector<pii> vect;
while (i < m) {
int v1 = ei - si;
int v2 = n - v1;
if (!vis[v1] && !vis[v2] && v1 != v2) {
vect.pb({si, ei});
vis[v1] = true;
vis[v2] = true;
si++;
ei--;
i++;
} else {
si++;
}
}
for (pii p : vect) {
cout << p.F << " " << p.S << "\n";
}
}
signed main() {
fast
#ifdef SWAPNIL07
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int)v.size()
#define pr(v) \
For(i, 0, sz(v)) { cout << v[i] << " "; } \
cout << endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for (ll i = st; i < en; i++)
#define tr(x) for (auto it = x.begin(); it != x.end(); it++)
#define fast \
std::ios::sync_with_stdio(false); \
cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 200005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
int begtime = clock();
#define end_routine() \
cout << "\n\nTime elapsed: " << (clock() - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
bool vis[N];
void solve() {
int n, m;
cin >> n >> m;
assert(n <= 200002);
int si = 1;
int ei = n;
int i = 0;
vector<pii> vect;
while (i < m) {
int v1 = ei - si;
int v2 = n - v1;
if (!vis[v1] && !vis[v2] && v1 != v2) {
vect.pb({si, ei});
vis[v1] = true;
vis[v2] = true;
si++;
ei--;
i++;
} else {
si++;
}
}
for (pii p : vect) {
cout << p.F << " " << p.S << "\n";
}
}
signed main() {
fast
#ifdef SWAPNIL07
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
while (t--) {
solve();
}
return 0;
}
| replace | 55 | 56 | 55 | 56 | 0 | |
p02697 | C++ | Runtime Error | // #include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
// cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a, b;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
if (n % 2) {
for (int i = 0; i < m; i++) {
cout << i + 1 << " " << n - i << "\n";
}
} else
return -1;
}
| // #include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
// cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a, b;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
if (n % 2) {
for (int i = 0; i < m; i++) {
cout << i + 1 << " " << n - i << "\n";
}
} else {
int j = 0;
int cur = n / 2;
int count = 0;
int d = 0;
bool c = false;
int dd = 0;
rep(i, m) {
if (count % 2) {
cout << 2 + dd << " " << n - dd << "\n";
dd++;
count++;
} else {
cout << cur - d << " " << cur + 1 + d << "\n";
d++;
count++;
}
}
}
}
| replace | 53 | 55 | 53 | 72 | 255 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<bool> checked(N + 1, false);
for (int i = M; i > 0; i--) {
for (int ai = 1; ai <= N; ai++) {
int bi = ai + i;
if (!checked.at(ai) && !checked.at(bi)) {
printf("%d %d\n", ai, bi);
checked.at(ai) = checked.at(bi) = true;
break;
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<bool> checked(N + 1, false);
int ai = 1;
for (int i = M; i > 0; i -= 2) {
printf("%d %d\n", ai, ai + i);
ai++;
}
ai = N;
for (int i = M - 1; i > 0; i -= 2) {
printf("%d %d\n", ai, ai - i);
ai--;
}
} | replace | 8 | 17 | 8 | 19 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod = 1000000007, INF = mod * mod * 3LL;
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
if (n & 1) {
ll id = 1;
vector<pair<ll, ll>> v(m);
for (int i = 0; i < n; i++) {
v[i].first = id;
id++;
}
id = n / 2 + 1;
for (int i = m - 1; i >= 0; i--) {
v[i].second = id;
id++;
}
for (auto &i : v) {
cout << i.first << " " << i.second << endl;
}
return 0;
}
ll a = n / 2, b;
if (a & 1)
b = a - 1, a -= 2;
else
b = a - 2, a--;
vector<pair<ll, ll>> v;
int idx = 1;
for (ll i = a; i >= 1; i -= 2, idx++) {
v.push_back({idx, idx + i});
}
idx = a + 2;
for (int i = b; i >= 1; i -= 2, idx++) {
v.push_back({idx, idx + i});
}
for (int i = 0; i < m; i++) {
cout << v[i].first << " " << v[i].second << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod = 1000000007, INF = mod * mod * 3LL;
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
if (n & 1) {
ll id = 1;
vector<pair<ll, ll>> v(m);
for (int i = 0; i < m; i++) {
v[i].first = id;
id++;
}
id = n / 2 + 1;
for (int i = m - 1; i >= 0; i--) {
v[i].second = id;
id++;
}
for (auto &i : v) {
cout << i.first << " " << i.second << endl;
}
return 0;
}
ll a = n / 2, b;
if (a & 1)
b = a - 1, a -= 2;
else
b = a - 2, a--;
vector<pair<ll, ll>> v;
int idx = 1;
for (ll i = a; i >= 1; i -= 2, idx++) {
v.push_back({idx, idx + i});
}
idx = a + 2;
for (int i = b; i >= 1; i -= 2, idx++) {
v.push_back({idx, idx + i});
}
for (int i = 0; i < m; i++) {
cout << v[i].first << " " << v[i].second << endl;
}
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p02697 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int IINF = INT32_MAX;
static const ll LINF = INT64_MAX;
static const ll mod = 1e9 + 7;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
int N, M;
bool f[200005];
bool usem[200005];
int main() {
cin >> N >> M;
if (N % 2 == 1) {
for (int i = 1; i <= M; ++i) {
cout << i << " " << N - i + 1 << endl;
}
} else {
int cnt = 0;
int t = N - 1;
int i = 1;
while (cnt < M) {
i %= N;
if (i == 0)
i = N;
int a = (i + t) % N;
int b = (i + N - t) % N;
if (a == 0)
a = N;
if (b == 0)
b = N;
if ((f[i] || f[a]) && (f[i] || f[b])) {
i++;
continue;
}
if (f[i] || f[a]) {
cout << i << " " << b << endl;
f[i] = f[b] = true;
} else {
cout << i << " " << a << endl;
f[i] = f[a] = true;
}
i++;
t--;
cnt++;
}
}
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int IINF = INT32_MAX;
static const ll LINF = INT64_MAX;
static const ll mod = 1e9 + 7;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
int N, M;
bool f[200005];
bool usem[200005];
int main() {
cin >> N >> M;
if (N % 2 == 1) {
for (int i = 1; i <= M; ++i) {
cout << i << " " << N - i + 1 << endl;
}
} else {
for (int i = 1; i <= M; ++i) {
if (N - 2 * i + 1 > 2 * i - 1)
cout << i << " " << N - i + 1 << endl;
else
cout << i << " " << N - i << endl;
}
}
} | replace | 43 | 70 | 43 | 48 | TLE | |
p02697 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
ll n, m;
cin >> n >> m;
set<ll> used;
ll left = 0, right = 0;
rep(i, m) {
right = (right + 1) % n;
while ((used.count(left) > 0) || (used.count(right) > 0)) {
left = (left + 1) % n;
right = (right + 1) % n;
}
used.insert(left);
used.insert(right);
printf("%lld %lld\n", left + 1, right + 1);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
ll n, m;
cin >> n >> m;
if (m == 1) {
printf("1 2\n");
return 0;
}
ll v1 = 1;
ll v2 = m + 2;
rreps(i, 1, m + 1) {
printf("%lld %lld\n", v1, v1 + i);
v1++;
swap(v1, v2);
}
return 0;
}
| replace | 20 | 31 | 20 | 30 | TLE | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))
const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;
inline int cmp(double x, double y = 0) {
if (fabs(x - y) < EPS)
return 0;
return x > y ? 1 : -1;
}
ll exp(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
const int maxn = 2e5 + 10;
int a[maxn];
map<int, int> mapa;
int main() {
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
set<int> s;
for (int i = 1; i <= n; i++)
s.insert(i);
int gap = 1;
for (int i = 1; i <= m; i++) {
assert(s.size() > 0);
int a = *s.begin();
cout << a << ' ' << a + gap << endl;
s.erase(s.find(a));
s.erase(s.find(a + gap));
gap++;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))
const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;
inline int cmp(double x, double y = 0) {
if (fabs(x - y) < EPS)
return 0;
return x > y ? 1 : -1;
}
ll exp(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
const int maxn = 2e5 + 10;
int a[maxn];
map<int, int> mapa;
int main() {
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
int l = 1, r = m + 1;
while (l < r)
cout << l++ << ' ' << r-- << endl;
l = m + 2, r = 2 * m + 1;
while (l < r)
cout << l++ << ' ' << r-- << endl;
return 0;
} | replace | 44 | 56 | 44 | 51 | 0 | |
p02697 | C++ | Time Limit Exceeded | // #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize(3)
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("sse3","sse2","sse")
// #pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
// #pragma GCC target("f16c")
// #pragma GCC
// optimize("inline","fast-math","unroll-loops","no-stack-protector") #pragma
// GCC diagnostic error "-fwhole-program" #pragma GCC diagnostic error
// "-fcse-skip-blocks" #pragma GCC diagnostic error
// "-funsafe-loop-optimizations" #pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x, "r", stdin)
#define fw(x) freopen(x, "w", stdout)
#define iout(x) printf("%d\n", x)
#define lout(x) printf("%lld\n", x)
#define REP(x, l, u) for (ll x = l; x < u; x++)
#define RREP(x, l, u) for (ll x = l; x >= u; x--)
#define complete_unique(a) a.erase(unique(a.begin(), a.end()), a.end())
#define mst(x, a) memset(x, a, sizeof(x))
#define all(a) begin(a), end(a)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define MP make_pair
#define lowbit(x) ((x) & (-(x)))
#define bitcnt(x) (__builtin_popcountll(x))
#define lson (ind << 1)
#define rson (ind << 1 | 1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace __gnu_pbds; // required
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ld eps = 1e-9;
const db PI = atan(1) * 4;
template <typename T> inline int sign(const T &a) {
if (a < 0)
return -1;
if (a > 0)
return 1;
return 0;
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) \
{}
#endif
template <typename T, typename S> inline bool upmin(T &a, const S &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T, typename S> inline bool upmax(T &a, const S &b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline void in(T &x) {
x = 0;
T f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
ull twop(ll x) { return 1ULL << x; }
ll MOD(ll a, ll m) {
a %= m;
if (a < 0)
a += m;
return a;
}
ll inverse(ll a, ll m) {
a = MOD(a, m);
if (a <= 1)
return a;
return MOD((1 - inverse(m, a) * m) / a, m);
}
template <typename A, typename B> inline void in(A &x, B &y) {
in(x);
in(y);
}
template <typename A, typename B, typename C> inline void in(A &x, B &y, C &z) {
in(x);
in(y);
in(z);
}
template <typename A, typename B, typename C, typename D>
inline void in(A &x, B &y, C &z, D &d) {
in(x);
in(y);
in(z);
in(d);
}
template <typename T> T sqr(T x) { return x * x; }
ll gcd(ll a, ll b) {
while (b != 0) {
a %= b;
swap(a, b);
}
return abs(a);
}
ll fast(ll a, ll b, ll mod) {
if (b < 0)
a = inverse(a, mod), b = -b;
ll ans = 1;
while (b) {
if (b & 1) {
b--;
ans = ans * a % mod;
} else {
a = a * a % mod;
b /= 2;
}
}
return ans % mod;
}
namespace SOLVE {
ll n, m;
void test(vector<PLL> prs, ll n) {
vector<char> v(n);
REP(i, 0, n) v[i] = i + 'A';
map<pair<char, char>, ll> cnt;
REP(i, 0, n) {
for (auto [a, b] : prs) {
cnt[MP(min(v[a - 1], v[b - 1]), max(v[a - 1], v[b - 1]))]++;
cerr << v[a - 1] << " " << v[b - 1] << " " << a << " " << b << endl;
}
v.insert(begin(v), v.back());
v.pop_back();
cerr << "--------\n";
}
for (auto i : cnt)
assert(i.se == 1);
}
void odd() {
ll l = n / 2, r = n / 2 + 1;
vector<PLL> v;
REP(i, 0, m) {
cout << l << " " << r << endl;
v.PB({l, r});
l--;
r++;
}
test(v, n);
}
void even() {
vector<PLL> v;
ll l = n / 2, r = n / 2 + 1;
REP(i, 0, m) {
if (r - l == n / 2 or r - l == n / 2 + 1)
l--;
v.push_back(make_pair(l, r));
l--;
r++;
}
// test(v,n);
for (auto i : v)
cout << i.fi << " " << i.se << endl;
}
void main() {
in(n, m);
if (n % 2 == 0)
even();
else
odd();
}
} // namespace SOLVE
signed main() {
#ifndef ONLINE_JUDGE
fr("/Users/zhangqingchuan/Desktop/cp/cp/input.txt");
fw("/Users/zhangqingchuan/Desktop/cp/cp/output.txt");
#endif
int t = 1;
// in(t);
for (int i = 1; i <= t; i++) {
// cout<<"Case #"<<i<<":";
SOLVE::main();
}
// clock_t st = clock();
// while(clock() - st < 3.0 * CLOCKS_PER_SEC){
//
// }
return 0;
}
| // #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize(3)
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("sse3","sse2","sse")
// #pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
// #pragma GCC target("f16c")
// #pragma GCC
// optimize("inline","fast-math","unroll-loops","no-stack-protector") #pragma
// GCC diagnostic error "-fwhole-program" #pragma GCC diagnostic error
// "-fcse-skip-blocks" #pragma GCC diagnostic error
// "-funsafe-loop-optimizations" #pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x, "r", stdin)
#define fw(x) freopen(x, "w", stdout)
#define iout(x) printf("%d\n", x)
#define lout(x) printf("%lld\n", x)
#define REP(x, l, u) for (ll x = l; x < u; x++)
#define RREP(x, l, u) for (ll x = l; x >= u; x--)
#define complete_unique(a) a.erase(unique(a.begin(), a.end()), a.end())
#define mst(x, a) memset(x, a, sizeof(x))
#define all(a) begin(a), end(a)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define MP make_pair
#define lowbit(x) ((x) & (-(x)))
#define bitcnt(x) (__builtin_popcountll(x))
#define lson (ind << 1)
#define rson (ind << 1 | 1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace __gnu_pbds; // required
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ld eps = 1e-9;
const db PI = atan(1) * 4;
template <typename T> inline int sign(const T &a) {
if (a < 0)
return -1;
if (a > 0)
return 1;
return 0;
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) \
{}
#endif
template <typename T, typename S> inline bool upmin(T &a, const S &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T, typename S> inline bool upmax(T &a, const S &b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline void in(T &x) {
x = 0;
T f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
ull twop(ll x) { return 1ULL << x; }
ll MOD(ll a, ll m) {
a %= m;
if (a < 0)
a += m;
return a;
}
ll inverse(ll a, ll m) {
a = MOD(a, m);
if (a <= 1)
return a;
return MOD((1 - inverse(m, a) * m) / a, m);
}
template <typename A, typename B> inline void in(A &x, B &y) {
in(x);
in(y);
}
template <typename A, typename B, typename C> inline void in(A &x, B &y, C &z) {
in(x);
in(y);
in(z);
}
template <typename A, typename B, typename C, typename D>
inline void in(A &x, B &y, C &z, D &d) {
in(x);
in(y);
in(z);
in(d);
}
template <typename T> T sqr(T x) { return x * x; }
ll gcd(ll a, ll b) {
while (b != 0) {
a %= b;
swap(a, b);
}
return abs(a);
}
ll fast(ll a, ll b, ll mod) {
if (b < 0)
a = inverse(a, mod), b = -b;
ll ans = 1;
while (b) {
if (b & 1) {
b--;
ans = ans * a % mod;
} else {
a = a * a % mod;
b /= 2;
}
}
return ans % mod;
}
namespace SOLVE {
ll n, m;
void test(vector<PLL> prs, ll n) {
vector<char> v(n);
REP(i, 0, n) v[i] = i + 'A';
map<pair<char, char>, ll> cnt;
REP(i, 0, n) {
for (auto [a, b] : prs) {
cnt[MP(min(v[a - 1], v[b - 1]), max(v[a - 1], v[b - 1]))]++;
cerr << v[a - 1] << " " << v[b - 1] << " " << a << " " << b << endl;
}
v.insert(begin(v), v.back());
v.pop_back();
cerr << "--------\n";
}
for (auto i : cnt)
assert(i.se == 1);
}
void odd() {
ll l = n / 2, r = n / 2 + 1;
vector<PLL> v;
REP(i, 0, m) {
cout << l << " " << r << endl;
v.PB({l, r});
l--;
r++;
}
// test(v,n);
}
void even() {
vector<PLL> v;
ll l = n / 2, r = n / 2 + 1;
REP(i, 0, m) {
if (r - l == n / 2 or r - l == n / 2 + 1)
l--;
v.push_back(make_pair(l, r));
l--;
r++;
}
// test(v,n);
for (auto i : v)
cout << i.fi << " " << i.se << endl;
}
void main() {
in(n, m);
if (n % 2 == 0)
even();
else
odd();
}
} // namespace SOLVE
signed main() {
#ifndef ONLINE_JUDGE
fr("/Users/zhangqingchuan/Desktop/cp/cp/input.txt");
fw("/Users/zhangqingchuan/Desktop/cp/cp/output.txt");
#endif
int t = 1;
// in(t);
for (int i = 1; i <= t; i++) {
// cout<<"Case #"<<i<<":";
SOLVE::main();
}
// clock_t st = clock();
// while(clock() - st < 3.0 * CLOCKS_PER_SEC){
//
// }
return 0;
}
| replace | 218 | 219 | 218 | 219 | TLE | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
int len = d.size();
rep(i, len) {
s << d[i];
if (i < len - 1)
s << " ";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
int len = d.size();
rep(i, len) { s << d[i] << endl; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const set<T> &v) {
s << "{ ";
for (auto itr = v.begin(); itr != v.end(); ++itr) {
if (itr != v.begin()) {
s << ", ";
}
s << (*itr);
}
s << " }";
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (auto itr = m.begin(); itr != m.end(); ++itr) {
s << " " << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
const ll mod = 1e9 + 7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
const double EPS = 1e-10;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
assert(n <= 100000);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
int len = d.size();
rep(i, len) {
s << d[i];
if (i < len - 1)
s << " ";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
int len = d.size();
rep(i, len) { s << d[i] << endl; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const set<T> &v) {
s << "{ ";
for (auto itr = v.begin(); itr != v.end(); ++itr) {
if (itr != v.begin()) {
s << ", ";
}
s << (*itr);
}
s << " }";
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (auto itr = m.begin(); itr != m.end(); ++itr) {
s << " " << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
const ll mod = 1e9 + 7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
const double EPS = 1e-10;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
ll r = 1, st = 1;
if (n % 2 == 1) {
ll en = n;
rep(i, m) {
cout << st << ' ' << en << endl;
st++;
en--;
}
return 0;
}
vector<bool> used(n, false);
ll en = n;
used[n / 2] = true;
rep(i, m) {
while (used[en - st] || used[n - (en - st)]) {
en--;
}
cout << st << ' ' << en << endl;
used[en - st] = used[n - (en - st)] = true;
st++;
en--;
}
} | replace | 80 | 81 | 80 | 102 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
bool U[100005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
vector<pll> ans;
if (N % 2 == 1) {
REP(i, M) { ans.push_back(pll(i + 1, N - 1 - i)); }
} else {
memset(U, 0, sizeof(U));
for (ll i = 1; i <= M; i += 2) {
ans.push_back(pll(i, i * 2));
U[i] = U[i * 2] = true;
}
ll m = (M / 2) * 2;
for (ll i = 2; i <= N; i += 2) {
if (i + m > N)
break;
if (U[i] || U[i + m])
continue;
ans.push_back(pll(i, i + m));
U[i] = U[i + m] = true;
m -= 2;
}
for (ll i = ((M / 2) * 2) + 1; i <= N; i += 2) {
if (i + m > N)
break;
if (U[i] || U[i + m])
continue;
ans.push_back(pll(i, i + m));
U[i] = U[i + m] = true;
m -= 2;
}
}
REP(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
bool U[100005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
vector<pll> ans;
if (N % 2 == 1) {
REP(i, M) { ans.push_back(pll(i + 1, N - 1 - i)); }
} else {
ll es = 1, os = N;
for (ll m = M; m > 0; --m) {
if (m % 2 == 0) {
ans.push_back(pll(es, es + m));
es++;
} else {
ans.push_back(pll(os, os - m));
os--;
}
}
}
REP(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
return 0;
} | replace | 25 | 50 | 25 | 34 | 0 | |
p02697 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define exrep(i, a, b) for (long long i = a; i <= b; i++)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll>> vvl;
typedef vector<vector<P>> vvp;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<P> vec;
if (n % 2) {
for (int l = 1, r = n - 1; l <= n / 2; l++, r--) {
vec.push_back(P(l, r));
}
} else {
int l = 1, r = n, cnt = 1;
while (cnt <= n / 4) {
vec.push_back(P(l, r));
l++;
r--;
cnt++;
}
l++;
while (abs(l - r) > 1) {
vec.push_back(P(l, r));
}
}
rep(i, m) { cout << vec[i].first << " " << vec[i].second << endl; }
return 0;
}
| #include <bits/stdc++.h>
#define exrep(i, a, b) for (long long i = a; i <= b; i++)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll>> vvl;
typedef vector<vector<P>> vvp;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<P> vec;
if (n % 2) {
for (int l = 1, r = n - 1; l <= n / 2; l++, r--) {
vec.push_back(P(l, r));
}
} else {
int l = 1, r = n, cnt = 1;
while (cnt <= n / 4) {
vec.push_back(P(l, r));
l++;
r--;
cnt++;
}
l++;
while (abs(l - r) > 1) {
vec.push_back(P(l, r));
l++;
r--;
}
}
rep(i, m) { cout << vec[i].first << " " << vec[i].second << endl; }
return 0;
}
| insert | 59 | 59 | 59 | 61 | TLE | |
p02697 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define repf(i, m, n) for (int i = (m); i < (n); i++)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////
int main() {
int n, m;
cin >> n >> m;
vector<bool> b(n, false);
int pos = 0, mn = 0;
repf(i, 1, m + 1) {
pos = mn;
if (b[pos + i]) {
pos++;
}
cout << pos + 1 << " " << pos + i + 1 << endl;
b[pos] = true;
b[pos + i] = true;
while (b[mn]) {
mn++;
}
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define repf(i, m, n) for (int i = (m); i < (n); i++)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////
int main() {
int n, m;
cin >> n >> m;
vector<bool> b(n, false);
int pos = 1, mx = 1;
for (int i = m; i >= 1; i -= 2) {
cout << pos << " " << pos + i << endl;
pos++;
chmax(mx, pos + i);
}
pos = mx;
for (int i = m - 1; i >= 1; i -= 2) {
cout << pos << " " << pos + i << endl;
pos++;
}
return 0;
} | replace | 36 | 48 | 36 | 46 | 0 | |
p02697 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
REP(WW, n) cerr << v[WW] << ' '; \
cerr << endl; \
}
#define SHOW2d(v, WW, HH) \
{ \
REP(W_, WW) { \
REP(H_, HH) cerr << v[W_][H_] << ' '; \
cerr << endl; \
} \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
vector<bool> used(111111);
ll now = n - 1;
for (ll i = 1; i <= m; i++) {
if (!used[now] && !used[n - now] && now != n - now) {
used[n - now] = true;
used[now] = true;
cout << i << " " << i + now << endl;
} else {
now--;
used[n - now] = true;
used[now] = true;
cout << i << " " << i + now << endl;
}
// cout << "now " << now << " " << n-now << endl;
now -= 2;
// SHOW1d(used, 10);
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
REP(WW, n) cerr << v[WW] << ' '; \
cerr << endl; \
}
#define SHOW2d(v, WW, HH) \
{ \
REP(W_, WW) { \
REP(H_, HH) cerr << v[W_][H_] << ' '; \
cerr << endl; \
} \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
vector<bool> used(222222);
ll now = n - 1;
for (ll i = 1; i <= m; i++) {
if (!used[now] && !used[n - now] && now != n - now) {
used[n - now] = true;
used[now] = true;
cout << i << " " << i + now << endl;
} else {
now--;
used[n - now] = true;
used[now] = true;
cout << i << " " << i + now << endl;
}
// cout << "now " << now << " " << n-now << endl;
now -= 2;
// SHOW1d(used, 10);
}
return 0;
}
| replace | 50 | 51 | 50 | 51 | 0 | |
p02697 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
#define mrep(i, n) for (ll i = n; i >= 0; --i)
#define all(a) (a).begin(), (a).end()
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pl pair<ll, ll>
#define inf 1001001001001001000
// #define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
/*
int main(void){
ll n,m,q;
cin>>n>>m>>q;
vvl quer(q,vl(4));
rep(i,q){
cin>>quer[i][0]>>quer[i][1]>>quer[i][2]>>quer[i][3];
}
rep(i,(1<<n)){
vl pitsu(n,-);
rep(j,n){
if(i&(1<<j) == 1){
ll now = pitsu[quer[j][1]-1]-pitsu[quer[j][0]-1];
if(now == pitsu[quer[j][2]]) continue;
else if(now < pitsu[quer[j][2]])
}
}
}
}
*/
int main(void) {
ll n, m;
cin >> n >> m;
vb a(n, false);
ll cnt = 0;
ll hue = 1;
rep(i, n) {
if (a[i] == false) {
a[i] = true;
a[i + hue] = true;
cout << i + 1 << " " << i + hue + 1 << endl;
cnt++;
hue++;
if (cnt == m)
break;
}
}
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
#define mrep(i, n) for (ll i = n; i >= 0; --i)
#define all(a) (a).begin(), (a).end()
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pl pair<ll, ll>
#define inf 1001001001001001000
// #define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
/*
int main(void){
ll n,m,q;
cin>>n>>m>>q;
vvl quer(q,vl(4));
rep(i,q){
cin>>quer[i][0]>>quer[i][1]>>quer[i][2]>>quer[i][3];
}
rep(i,(1<<n)){
vl pitsu(n,-);
rep(j,n){
if(i&(1<<j) == 1){
ll now = pitsu[quer[j][1]-1]-pitsu[quer[j][0]-1];
if(now == pitsu[quer[j][2]]) continue;
else if(now < pitsu[quer[j][2]])
}
}
}
}
*/
int main(void) {
ll n, m;
cin >> n >> m;
vb a(n, false);
ll cnt = 0;
ll hue = 1;
if (m % 2 == 0) {
rep(i, m / 2) { cout << i + 1 << " " << m - i + 1 << endl; }
rep(i, m / 2) { cout << m + 1 + i + 1 << " " << 2 * m - i + 1 << endl; }
} else {
rep(i, m / 2 + 1) { cout << i + 1 << " " << m + 1 - i << endl; }
rep(i, m / 2) { cout << i + m + 2 << " " << 2 * m + 1 - i << endl; }
}
} | replace | 61 | 71 | 61 | 67 | 0 | |
p02697 | C++ | Runtime Error | // g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
int main() {
ll N, M;
cin >> N >> M;
ll a, b;
a = 3;
b = 5;
if (M >= 1)
cout << 1 << " " << 2 << endl;
if (M >= 2)
cout << 3 << " " << 5 << endl;
vector<int> flag(200010, 1);
flag[1] = 0;
flag[2] = 0;
flag[3] = 0;
flag[5] = 0;
if (M >= 3) {
int i = 3;
while (i <= M) {
a++;
if (flag[a] == 1 && flag[a + i] == 1) {
b = a + i;
cout << a << " " << b << endl;
flag[a] = 0;
flag[b] = 0;
i++;
}
}
}
}
| // g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
int main() {
ll N, M;
cin >> N >> M;
int a = N;
int b = 1 + M;
int flag = 1;
for (int i = 1; i <= M; i++) {
if (flag % 2 == 1) {
cout << b << " " << b + i << endl;
b--;
flag--;
} else {
cout << a << " " << a - (N - i) << endl;
a--;
flag++;
}
}
}
| replace | 30 | 53 | 30 | 42 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v, x) memset(v, x, sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(), v.end()
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
int eu = 1, ini = 2;
vector<int> vis(100100);
for (int i = 1; i <= m; i++) {
cout << eu << " " << ini << endl;
vis[eu] = 1;
vis[ini] = 1;
while (vis[eu] or vis[ini]) {
eu++;
ini += 2;
if (ini > n) {
ini -= n;
}
if (eu > n) {
eu -= n;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1, l = 1;
// cin >> t;
while (t--) {
solve();
}
} | #include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v, x) memset(v, x, sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(), v.end()
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
int val = 2 * m + 1;
for (int i = 0; i < m / 2; i++) {
cout << i + 1 << " " << val / 2 - i << endl;
}
int cnt = 1;
for (int i = m / 2; i < m; i++) {
cout << val / 2 + cnt << " " << val - (cnt - 1) << endl;
cnt++;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1, l = 1;
// cin >> t;
while (t--) {
solve();
}
} | replace | 15 | 31 | 15 | 23 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
if (N % 2 != 0 || N == 4) {
// 真ん中から割って割り当てる
int cur1 = N / 2;
int cur2 = cur1 + 1;
REP(i, M) {
printf("%lld %lld\n", cur1, cur2);
cur1--;
cur2++;
}
} else {
assert(false);
// 末尾を 1 つ飛ばしで開ける
int cur1 = 1;
int cur2 = N - 1;
REP(i, M) {
printf("%lld %lld\n", cur1, cur2);
cur1++;
cur2--;
if (i == 0) {
cur2--;
}
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
if (N % 2 != 0 || N == 4) {
// 真ん中から割って割り当てる
int cur1 = N / 2;
int cur2 = cur1 + 1;
REP(i, M) {
printf("%lld %lld\n", cur1, cur2);
cur1--;
cur2++;
}
} else {
// 空ける間隔で偶奇に分けて詰めていく
// 偶数(奇数)間隔から
int lb = 1;
int rb = lb + M;
while (lb < rb) {
printf("%lld %lld\n", lb, rb);
lb++;
rb--;
}
// 奇数(偶数)間隔
lb = M + 2;
rb = lb + M - 1;
while (lb < rb) {
printf("%lld %lld\n", lb, rb);
lb++;
rb--;
}
}
return 0;
}
| replace | 49 | 60 | 49 | 65 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
if (n & 1) {
for (int i = 0; i < m; ++i) {
cout << i + 1 << ' ' << n - i - (n & 1) << '\n';
}
} else {
vector<int> a;
a.resize(1000000000000000);
for (int i = 0; i <= m / 2; ++i) {
cout << i + 1 << ' ' << n - i << '\n';
}
for (int i = m / 2 + 1; i < m; ++i) {
cout << i + 1 << ' ' << n - i - 1 << '\n';
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 1; i * 2 <= m; ++i) {
cout << i << ' ' << m - i + 1 << '\n';
}
for (int i = 1; i * 2 <= m + 1; ++i) {
cout << m + i << ' ' << m * 2 - i + 2 << '\n';
}
return 0;
}
| replace | 11 | 24 | 11 | 17 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool u[100010];
long long n, m, x;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> m;
int i = 1;
int j = n;
while (m--) {
x = j - i - 2;
if (!u[x] && !u[n - x - 2]) {
u[x] = u[n - x - 2] = true;
cout << i << ' ' << j << '\n';
i++, j--;
} else
j--, m++;
}
}
| #include <bits/stdc++.h>
using namespace std;
bool u[1000010];
long long n, m, x;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> m;
int i = 1;
int j = n;
while (m--) {
x = j - i - 2;
if (!u[x] && !u[n - x - 2]) {
u[x] = u[n - x - 2] = true;
cout << i << ' ' << j << '\n';
i++, j--;
} else
j--, m++;
}
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02697 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
signed main() {
int n, m;
cin >> n >> m;
vector<int> used(n, 0);
int now = 0;
for (int i = 1; i <= m; i++) {
int a = now + i;
while (used[now] || used[a])
(++now) %= n, (++a) %= n;
cout << now + 1 << " " << a + 1 << endl;
used[now] = used[a] = 1;
}
}
| #include <bits/stdc++.h>
using namespace std;
signed main() {
int n, m;
cin >> n >> m;
int cnt = 1;
for (int i = m; i >= 1; i -= 2) {
cout << cnt << " " << cnt + i << endl;
cnt++;
}
cnt = m + 2;
for (int i = m - 1; i >= 1; i -= 2) {
cout << cnt << " " << cnt + i << endl;
cnt++;
}
}
| replace | 6 | 14 | 6 | 15 | TLE | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
int main() {
ll N, M;
cin >> N >> M;
ll head = 2 * (M / 2) + 1;
if (M % 2 == 0)
return 1;
rep(i, 1, M / 2 + 1) {
cout << i << " " << head << endl;
head--;
}
head = 2 * (M / 2) + 1 + 2 * (M + 1) / 2;
rep(i, 1, (M + 1) / 2 + 1) {
cout << i + 2 * (M / 2) + 1 << " " << head << endl;
head--;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
int main() {
ll N, M;
cin >> N >> M;
ll head = 2 * (M / 2) + 1;
if (M % 2 == 0) {
rep(i, 1, M / 2 + 1) {
cout << i << " " << head << endl;
head--;
}
head = 2 * (M / 2) + 1 + 2 * (M) / 2;
rep(i, 1, (M) / 2 + 1) {
cout << i + 2 * (M / 2) + 1 << " " << head << endl;
head--;
}
} else {
rep(i, 1, M / 2 + 1) {
cout << i << " " << head << endl;
head--;
}
head = 2 * (M / 2) + 1 + 2 * (M + 1) / 2;
rep(i, 1, (M + 1) / 2 + 1) {
cout << i + 2 * (M / 2) + 1 << " " << head << endl;
head--;
}
}
return 0;
} | replace | 9 | 19 | 9 | 29 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define debug(x) \
cout << #x << ":"; \
cout << x << endl;
#define debugs(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
#define INF 1000000000
#define mod 1000000007
using ll = long long;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
ll n, m;
cin >> n >> m;
if (n % 2) {
ll l = 1, r = n - 1;
rep(i, m) {
cout << l << " " << r << endl;
l++, r--;
}
return 0;
} else {
ll l = 1, r = n;
rep(i, m) {
cout << l << " " << r << endl;
l++, r--;
if (r - l == n / 2) {
r--;
assert(false);
}
}
return 0;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define debug(x) \
cout << #x << ":"; \
cout << x << endl;
#define debugs(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
#define INF 1000000000
#define mod 1000000007
using ll = long long;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
ll n, m;
cin >> n >> m;
if (n % 2) {
ll l = 1, r = n - 1;
rep(i, m) {
cout << l << " " << r << endl;
l++, r--;
}
return 0;
} else {
ll l = 1, r = n;
if ((n / 2) % 2) {
rep(i, m) {
cout << l << " " << r << endl;
l++, r--;
if (r - l == n / 2) {
r--;
}
}
} else {
ll l = 1, r = n;
set<pair<ll, ll>> st;
bool f = true;
rep(i, m) {
cout << l << " " << r << endl;
l++, r--;
ll x = r - l;
ll y = n - x;
if (f and st.count(make_pair(max(x, y), min(x, y)))) {
r--;
f = false;
}
st.insert(make_pair(max(x, y), min(x, y)));
}
}
return 0;
}
return 0;
}
| replace | 50 | 56 | 50 | 72 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
for (int i = 0; i < sz(v); i++) {
os << v[i];
if (i < sz(v) - 1)
os << " ";
}
return os;
}
int main() {
int n, m;
cin >> n >> m;
set<int> st;
for (int i = 1; i <= n; i++)
st.insert(i);
for (int i = 1; i <= m; i++) {
int a = *st.begin();
st.erase(a);
int b = a + i;
st.erase(b);
assert(b <= n);
cout << a << " " << b << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
for (int i = 0; i < sz(v); i++) {
os << v[i];
if (i < sz(v) - 1)
os << " ";
}
return os;
}
int main() {
int n, m;
cin >> n >> m;
{
int a = 1, b = m + 1;
for (int i = m; i >= 1; i -= 2) {
assert(b <= n);
cout << a << " " << b << endl;
a++;
b--;
}
}
{
int a = m + 2, b = 2 * m + 1;
for (int i = m - 1; i >= 1; i -= 2) {
assert(b <= n);
cout << a << " " << b << endl;
a++;
b--;
}
}
}
| replace | 41 | 51 | 41 | 58 | 0 | |
p02697 | C++ | Runtime Error | #ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FAST ;
#else
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ << ' ' <<
#define Fr(i, s, e) for (auto i = s; i < e; ++i)
#define All(v) v.begin(), v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 998'244'353;
signed main() {
FAST;
int n, m;
cin >> n >> m;
assert(n % 2);
}
| #ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FAST ;
#else
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ << ' ' <<
#define Fr(i, s, e) for (auto i = s; i < e; ++i)
#define All(v) v.begin(), v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 998'244'353;
signed main() {
FAST;
int n, m;
cin >> n >> m;
Fr(i, 0, m / 2) cout _ i + 1 _ m / 2 * 2 + 1 - i _ endl;
Fr(i, 0, (m + 1) / 2) cout _ m / 2 * 2 + 2 + i _ m * 2 + 1 - i _ endl;
}
| replace | 30 | 31 | 30 | 32 | -6 | a177d33b-97e6-4253-9097-fb4171dcc210.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s908641400.cpp:29: int main(): Assertion `n%2' failed.
|
p02697 | Python | Runtime Error | N, M = map(int, input().split())
sieve = [0] * (100000 + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, 100000 + 1):
if sieve[i] != 0:
continue
sieve[i] = i
for j in range(i * i, 100000 + 1, i):
if sieve[j] == 0:
sieve[j] = i
p = []
for i in range(N - 1, -1, -1):
if sieve[i] == i:
p.append(i)
p.append(1)
t = set()
pp = 0
for i in range(M):
x = i + 1
y = x + p[pp]
while y in t:
pp += 1
y = x + p[pp]
t.add(x)
t.add(y)
print(x, y)
pp += 1
| N, M = map(int, input().split())
for i in range(1, M + 1):
if i % 2 == 1:
j = (i - 1) // 2
print(1 + j, M + 1 - j)
else:
j = (i - 2) // 2
print(M + 2 + j, 2 * M + 1 - j)
| replace | 2 | 31 | 2 | 9 | 0 | |
p02697 | Python | Runtime Error | n, m = map(int, input().split())
a, b = n, 1
V = [False for d in range(1, m + 2)]
for i in range(m):
d = min(a - b, n - (a - b))
if 2 * d == n or V[d]:
a -= 1
print(a, b)
d = min(a - b, n - (a - b))
V[d] = True
a -= 1
b += 1
| n, m = map(int, input().split())
a, b = n, 1
V = [False for d in range(1, n + 1)]
for i in range(m):
d = min(a - b, n - (a - b))
if 2 * d == n or V[d]:
a -= 1
print(a, b)
d = min(a - b, n - (a - b))
V[d] = True
a -= 1
b += 1
| replace | 2 | 3 | 2 | 3 | 0 | |
p02697 | C++ | Runtime Error | #pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;
#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
//------ Believe yourself as a genius!!!!!! ------
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
bool vi[ohara], mode;
int main(void) {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
if (m < 1 || n > 100000 || m * 2 + 1 > n)
return -1;
if (n % 2 == 1) {
ans = 1;
tmp = n;
rep(i, m) {
cout << ans << " " << tmp << "\n";
ans++;
tmp--;
}
} else {
ans = 1;
tmp = n;
ll lim = (n - 1) / 2;
rep(i, m) {
if (i + 1 <= (lim + 1) / 2)
cout << i + 1 << " " << n - i << "\n";
else
cout << i + 1 << " " << n - i - 1 << "\n";
}
}
// Cout(ans);
return 0;
}
| #pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;
#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
//------ Believe yourself as a genius!!!!!! ------
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
bool vi[ohara], mode;
int main(void) {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
// if (m < 1 || n > 100000 || m * 2 + 1 > n) return -1;
if (n % 2 == 1) {
ans = 1;
tmp = n;
rep(i, m) {
cout << ans << " " << tmp << "\n";
ans++;
tmp--;
}
} else {
ans = 1;
tmp = n;
ll lim = (n - 1) / 2;
rep(i, m) {
if (i + 1 <= (lim + 1) / 2)
cout << i + 1 << " " << n - i << "\n";
else
cout << i + 1 << " " << n - i - 1 << "\n";
}
}
// Cout(ans);
return 0;
}
| replace | 67 | 69 | 67 | 68 | 0 | |
p02697 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
if (n % 2) {
int dif = 1;
int pivot = n / 2;
for (int i = 0; i < m; i++) {
cout << pivot << " " << pivot + dif << endl;
pivot--;
dif += 2;
}
} else {
vector<bool> used(n + 1, false);
int dif = 0;
int pivot = 0;
for (int i = 0; i < m; i++) {
pivot = pivot % n + 1;
int l = pivot;
int r = (pivot + dif) % n + 1;
if (used[l] || used[r]) {
i--;
continue;
}
cout << l << " " << r << endl;
used[l] = true;
used[r] = true;
dif++;
}
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
if (n % 2) {
int dif = 1;
int pivot = n / 2;
for (int i = 0; i < m; i++) {
cout << pivot << " " << pivot + dif << endl;
pivot--;
dif += 2;
}
} else {
int dif = 1;
int pivot = n / 2;
int i = 0;
for (; i < m; i++) {
if (i >= n / 4)
break;
cout << pivot << " " << pivot + dif << endl;
pivot--;
dif += 2;
}
dif++;
for (; i < m; i++) {
cout << pivot << " " << pivot + dif << endl;
pivot--;
dif += 2;
}
}
return 0;
}
| replace | 21 | 36 | 21 | 36 | TLE | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int m, n, tr, cnta, cntb;
int a[50005], b[50005];
int lo(int start, int step) { return (start + step + n - 1) % n + 1; }
int main() {
cin >> n >> m;
cnta = 1;
cntb = n;
for (int i = 0; i < m; i++) {
if (i % 2 == 0) {
a[i] = cnta;
b[i] = lo(cnta, m - i);
cnta++;
} else {
a[i] = cntb;
b[i] = lo(cntb, i - m);
cntb--;
}
}
for (int i = 0; i < m; i++) {
cout << a[i] << ' ' << b[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int m, n, tr, cnta, cntb;
int a[100005], b[100005];
int lo(int start, int step) { return (start + step + n - 1) % n + 1; }
int main() {
cin >> n >> m;
cnta = 1;
cntb = n;
for (int i = 0; i < m; i++) {
if (i % 2 == 0) {
a[i] = cnta;
b[i] = lo(cnta, m - i);
cnta++;
} else {
a[i] = cntb;
b[i] = lo(cntb, i - m);
cntb--;
}
}
for (int i = 0; i < m; i++) {
cout << a[i] << ' ' << b[i] << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VP vector<pair<int, int>>
#define VPP vector<pair<int, pair<int, int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;
int main() {
int n, m;
cin >> n >> m;
if (n % 2 == 1) {
REP(i, m) { cout << i + 1 << ' ' << m * 2 - i << endl; }
} else {
assert(n == 0);
REP(i, m) { cout << i + 1 << ' ' << n - i << endl; }
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VP vector<pair<int, int>>
#define VPP vector<pair<int, pair<int, int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;
int main() {
int n, m;
cin >> n >> m;
if (n % 2 == 1) {
REP(i, m) { cout << i + 1 << ' ' << m * 2 - i << endl; }
} else {
if (m % 2 == 0) {
REP(i, m / 2) { cout << i + 1 << ' ' << m - i << endl; }
REP(i, m / 2) { cout << m + 2 + i << ' ' << m * 2 + 2 - i << endl; }
} else {
REP(i, m / 2 + 1) { cout << i + 1 << ' ' << m + 1 - i << endl; }
REP(i, m / 2) { cout << m + 3 + i << ' ' << m * 2 + 2 - i << endl; }
}
}
}
| replace | 50 | 52 | 50 | 57 | -6 | 78faeead-fa29-4e44-823c-5bcba8858b4e.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s094347515.cpp:43: int main(): Assertion `n == 0' failed.
|
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define tmax(a, b, c) max(a, max(b, c))
#define tmin(a, b, c) min(a, min(b, c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (T &t : v) {
is >> t;
}
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (T t : v) {
os << t << " ";
}
os << "\n";
return os;
}
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
vb used(n, false);
int now = 0;
rep2(i, 1, m + 1) {
while (used[now])
now++;
used[now] = true;
used[now + i] = true;
cout << now + 1 << " " << now + i + 1 << endl;
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define tmax(a, b, c) max(a, max(b, c))
#define tmin(a, b, c) min(a, min(b, c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (T &t : v) {
is >> t;
}
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (T t : v) {
os << t << " ";
}
os << "\n";
return os;
}
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
int l = 1, r = 1 + m;
while (l < r) {
cout << l << " " << r << endl;
l++;
r--;
}
l = m + 2, r = l + m - 1;
while (l < r) {
cout << l << " " << r << endl;
l++;
r--;
}
}
| replace | 59 | 67 | 59 | 70 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define MOD 1000000007
signed main() {
SPEED;
int n, m;
cin >> n >> m;
int i = 1, j = 2 * m;
assert(m % 2);
for (int t = 0; t < m; t++) {
cout << i << " " << j << endl;
++i;
--j;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define MOD 1000000007
signed main() {
SPEED;
int n, m;
cin >> n >> m;
if (n % 2 == 1) {
int i = 1, j = 2 * m;
for (int t = 0; t < m; t++) {
cout << i << " " << j << endl;
++i;
--j;
}
} else {
int i = 1, j = n, f = 1;
for (int t = 0; t < m; ++t) {
if (t >= n / 4 && f == 1) {
--j;
f = -1;
}
cout << i << " " << j << endl;
++i;
--j;
}
}
} | replace | 13 | 19 | 13 | 31 | 0 | |
p02697 | C++ | Runtime Error | // #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define endl '\n'
#define pll pair<long long, long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
if (n & 1) {
n--;
for (int i = 0; i < m; i++) {
cout << i + 1 << " " << n - i << endl;
}
} else {
assert(false);
}
return 0;
}
| // #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define endl '\n'
#define pll pair<long long, long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
if (n & 1) {
n--;
for (int i = 0; i < m; i++) {
cout << i + 1 << " " << n - i << endl;
}
} else {
for (int i = 0; i < m; i++) {
if (i < (m + 1) / 2)
cout << i + 1 << " " << n - i << endl;
else
cout << i + 1 << " " << n - i - 1 << endl;
}
}
return 0;
}
| replace | 43 | 44 | 43 | 50 | -6 | fac7754b-8485-4e4f-9ea8-3c2e00bb8ea4.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s479002330.cpp:43: int32_t main(): Assertion `false' failed.
|
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(x, a) for (auto x : a)
/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))
/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl
/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;
ll N, M;
ll ret = 0;
string s;
int main(void) {
IN(N);
IN(M);
vl arr(N + 1, 0);
ll left = 1;
ll right;
FOR(i, 1, M + 1) {
right = left + i;
cout << left << " " << right << endl;
arr[left] = 1;
arr[right] = 1;
while (left < N + 1 && arr[left] == 1) {
left++;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(x, a) for (auto x : a)
/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))
/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl
/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;
ll N, M;
ll ret = 0;
string s;
int main(void) {
IN(N);
IN(M);
ll l = 1;
ll r = l + (M % 2 == 1 ? M : M - 1);
while (r > l) {
cout << l << " " << r << endl;
l++;
r--;
}
r = 2 * M + 1;
l = r - (M % 2 == 0 ? M : M - 1);
while (r > l) {
cout << l << " " << r << endl;
l++;
r--;
}
}
| replace | 46 | 57 | 46 | 59 | 0 | |
p02697 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define R 1000000007
#define M 998244353
#define grid vector<vector<long long>>
#define L 256
long long mx = INT32_MIN, mn = INT32_MAX;
struct maths_util {
vector<long long> fact;
vector<bool> is_prime;
maths_util(int n = 200001, long long q = R) {
fact.resize(n);
is_prime.assign(n + 1, true);
fact[0] = 1;
for (int i = 1; i < n; i++)
fact[i] = (fact[i - 1] * i) % q;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++)
if (is_prime[i])
for (int j = i + i; j <= n; j += i)
is_prime[j] = false;
}
long long power_mod_q(long long x, long long n, long long q = R) {
if (n == 0)
return 1;
if (n % 2 == 0)
return power_mod_q((x * x) % q, n / 2, q);
else
return (x * power_mod_q((x * x) % q, n / 2, q)) % q;
}
long long inverse_mod_q(long long n, long long q = R) {
return power_mod_q(n, q - 2, q);
}
long long nCr_mod_q(long long n, long long r, long long q = R) {
return (((fact[n] * inverse_mod_q(fact[r], q)) % q) *
inverse_mod_q(fact[n - r], q)) %
q;
}
long long power(long long x, long long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return power(x * x, n / 2);
else
return x * power(x * x, n / 2);
}
grid multiply(grid &a, grid &b) {
int p = a.size(), q = b.size(), r = b[0].size();
grid c(p, vector<long long>(r, 0));
for (int i = 0; i < p; i++)
for (int j = 0; j < r; j++)
for (int k = 0; k < q; k++)
c[i][j] += a[i][k] * b[k][j];
return c;
}
grid add(grid &a, grid &b) {
int p = a.size(), q = a[0].size();
grid c(p, vector<long long>(q));
for (int i = 0; i < p; i++)
for (int j = 0; j < q; j++)
c[i][j] = a[i][j] + b[i][j];
return c;
}
grid power(grid &a, long long n) {
grid c(a.size(), vector<long long>(a.size(), 0));
if (n == 0) {
for (int i = 0; i < a.size(); i++)
c[i][i] = 1;
return c;
}
if (n % 2 == 0)
return power(c = multiply(a, a), n / 2);
else
return multiply(a, c = power(c = multiply(a, a), n / 2));
}
} u;
struct dsu {
vector<int> rank, parent, num;
dsu(int n) {
rank.assign(n, 0);
parent.resize(n);
for (int i = 0; i < n; i++)
parent[i] = i;
}
int find_set(int i) {
if (i == parent[i])
return i;
return parent[i] = find_set(parent[i]);
}
bool is_same_set(int i, int j) {
if (find_set(i) == find_set(j))
return true;
return false;
}
void union_set(int i, int j) {
if (!is_same_set(i, j)) {
int u = find_set(i), v = find_set(j);
if (rank[u] == rank[v]) {
parent[v] = u;
rank[u] += 1;
} else if (rank[u] > rank[v])
parent[v] = u;
else
parent[u] = v;
}
}
};
struct graph {
int v, time, count;
vector<pair<int, int>> *adj;
vector<bool> visited, in_stack, ap, in_MST;
stack<int> s;
vector<int> color, cc, d, f, l, finish_time, indegree, sccs, topo, outdegree,
pred, child;
graph(int n) {
v = n;
adj = new vector<pair<int, int>>[n];
visited.assign(n, false);
in_stack.assign(n, false);
ap.assign(n, false);
color.assign(n, 0);
cc.assign(n, -1);
d.assign(n, -1);
f.assign(n, -1);
indegree.assign(n, 0);
outdegree.assign(n, 0);
pred.assign(n, -1);
child.assign(n, 0);
time = count = 0;
finish_time.assign(2 * n, -1);
l.assign(n, 0);
}
void add_edge(int u, int v, int w) {
adj[u].push_back(make_pair(v, w));
adj[v].push_back(make_pair(u, w));
}
void dfs() {
color.assign(v, 0);
cc.assign(v, -1);
time = count = 0;
finish_time.assign(2 * v, -1);
visited.assign(v, false);
pred.assign(v, -1);
for (int i = 0; i < v; i++) {
if (color[i] == 0) {
dfs(i);
count++;
}
}
for (int i = 0; i < v; i++)
finish_time[f[i]] = i;
}
void dfs(int i) {
color[i] = 1;
cc[i] = count;
d[i] = time;
time++;
for (auto x : adj[i]) {
if (color[x.first] == 0) {
pred[x.first] = i;
dfs(x.first);
}
}
color[i] = 2;
f[i] = time;
time++;
}
void scc() {
graph g_t(v);
for (int i = 0; i < v; i++)
for (auto x : adj[i])
g_t.add_edge(x.first, i, x.second);
dfs();
for (int i = 2 * v - 1; i >= 0; i--) {
if (finish_time[i] != -1 && g_t.color[finish_time[i]] == 0) {
g_t.dfs(finish_time[i]);
g_t.count++;
}
}
sccs = g_t.cc;
count = g_t.count;
}
void topological_sort() {
for (int i = 0; i < v; i++)
if (adj[i].size())
outdegree[i] = adj[i].size();
for (int i = 0; i < v; i++)
for (auto x : adj[i])
indegree[x.first]++;
vector<int> zero;
for (int i = 0; i < v; i++)
if (!indegree[i])
zero.push_back(i);
while (!zero.empty()) {
int v = zero.back();
topo.push_back(v);
zero.pop_back();
for (auto x : adj[v]) {
indegree[x.first]--;
if (!indegree[x.first])
zero.push_back(x.first);
}
}
}
void tarjan() {
for (int i = 0; i < v; i++)
if (!color[i])
tarjan(i);
}
void tarjan(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
s.push(i);
in_stack[i] = true;
for (auto x : adj[i]) {
if (!color[x.first]) {
tarjan(x.first);
l[i] = min(l[i], l[x.first]);
} else if (in_stack[x.first]) {
l[i] = min(l[i], d[x.first]);
}
}
color[i] = 2;
f[i] = time;
time++;
if (d[i] == l[i]) {
while (s.top() != i)
cout << s.top() << ' ', in_stack[s.top()] = false, s.pop();
cout << s.top() << '\n', in_stack[s.top()] = false, s.pop();
}
}
// incomplete --->
void articulate() {
ap.assign(v, false);
color.assign(v, 0);
child.assign(v, 0);
time = 0;
d.assign(v, -1);
f.assign(v, -1);
l.assign(v, 0);
pred.assign(v, -1);
for (int i = 0; i < v; i++)
if (color[i] == 0) {
articulate(i);
if (child[i] == 1 || child[i] == 0)
ap[i] = false;
}
}
void articulate(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
for (auto x : adj[i]) {
if (pred[i] != x.first && color[x.first] == 1)
l[i] = min(l[i], d[x.first]);
if (!color[x.first]) {
pred[x.first] = i;
child[i]++;
articulate(x.first);
l[i] = min(l[i], l[x.first]);
}
if (l[x.first] >= d[i])
ap[i] = true;
}
f[i] = time;
time++;
color[i] = 2;
}
// incomplete --->
void bridges() {
time = 0;
f.assign(v, -1);
d.assign(v, -1);
l.assign(v, 0);
color.assign(v, 0);
pred.assign(v, -1);
for (int i = 0; i < v; i++)
if (color[i] == 0)
bridge(i);
}
void bridge(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
for (auto itr = adj[i].begin(); itr != adj[i].end(); itr++) {
if (pred[i] != itr->first && color[itr->first] == 1)
l[i] = min(l[i], d[itr->first]);
if (!color[itr->first]) {
pred[itr->first] = i;
bridge(itr->first);
l[i] = min(l[i], l[itr->first]);
}
if (l[itr->first] > d[i])
itr->second = 1;
}
color[i] = 2;
f[i] = time;
time++;
}
graph kruskal() {
vector<pair<int, pair<int, int>>> edges;
for (int i = 0; i < v; i++)
for (auto x : adj[i])
edges.push_back(make_pair(x.second, make_pair(i, x.first)));
sort(edges.begin(), edges.end());
dsu d(v);
graph mst(v);
for (auto x : edges) {
if (!d.is_same_set(x.second.first, x.second.second)) {
mst.add_edge(x.second.first, x.second.second, x.first);
d.union_set(x.second.first, x.second.second);
}
}
return mst;
}
graph prims(int s) {
priority_queue<pair<int, int>, vector<pair<int, int>>,
greater<pair<int, int>>>
pq;
d.assign(v, INT32_MAX);
pred.assign(v, -1);
in_MST.assign(v, false);
count = 0;
d[s] = 0;
pq.push({0, s});
while (count < v) {
int u = pq.top().second;
if (!in_MST[u])
in_MST[u] = true, count++;
pq.pop();
for (auto x : adj[u]) {
if (!in_MST[x.first] && d[x.first] > x.second) {
pq.push({x.second, x.first});
pred[x.first] = u;
d[x.first] = x.second;
}
}
}
graph mst(v);
for (int i = 0; i < v; i++) {
if (pred[i] != -1)
mst.add_edge(i, pred[i], d[i]);
}
return mst;
}
};
struct kmp {
vector<int> lps;
string p, t;
kmp(string &p, string &t) {
this->p = p;
this->t = t;
// PREPROCESSING
lps.assign(p.size(), 0);
lps[0] = 0;
int len = 0, i = 1, j;
while (i < p.size()) {
if (p[i] == p[len])
lps[i++] = ++len;
else if (len)
len = lps[len - 1];
else
lps[i++] = 0;
}
// STRING MATCHING
i = j = 0;
while (i < t.size()) {
if (p[j] == t[i])
j++, i++;
if (j == p.size()) {
// It's a match at index i - 1
j = lps[j - 1];
} else if (i < t.size() && p[j] != t[i]) {
if (j)
j = lps[j - 1];
else
i++;
}
}
}
};
// Pending lazy --->
struct segment_tree {
int n;
vector<int> a, tree;
segment_tree(vector<int> &a) {
this->n = a.size();
this->a = a;
tree.resize(4 * n);
build(0, 0, n - 1);
}
void build(int node, int l, int r) {
if (l == r)
tree[node] = a[r];
else {
int mid = (l + r) / 2;
build(2 * node + 1, l, mid);
build(2 * node + 2, mid + 1, r);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
}
void update(int node, int l, int r, int i, int x) {
if (l == r)
tree[node] = a[i] = x;
else {
int mid = (l + r) / 2;
if (i <= mid && i >= l)
update(2 * node + 1, l, mid, i, x);
else
update(2 * node + 2, mid + 1, r, i, x);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
}
int query(int node, int l, int r, int ql, int qr) {
if (l == ql && r == qr)
return tree[node];
else {
int mid = (l + r) / 2;
if (qr <= mid)
return query(2 * node + 1, l, mid, ql, qr);
else if (ql > mid)
return query(2 * node + 2, mid + 1, r, ql, qr);
else
return query(2 * node + 1, l, mid, ql, mid) +
query(2 * node + 2, mid + 1, r, mid + 1, qr);
}
}
};
struct trie {
struct node {
char c;
bool is_leaf;
vector<node *> child;
node(char ch) {
c = ch;
is_leaf = false;
child.assign(L, nullptr);
}
};
node *root;
trie() { root = new node('#'); }
void insert(string &s) {
node *temp = root;
for (auto x : s) {
if (!(temp->child)[x])
(temp->child)[x] = new node(x);
temp = (temp->child)[x];
}
temp->is_leaf = true;
}
bool has_child(node *temp) {
for (auto x : temp->child)
if (x)
return true;
return false;
}
bool search(string &s) {
node *temp = root;
bool flag = true;
for (auto x : s) {
if (!(temp->child)[x]) {
flag = false;
break;
}
temp = (temp->child)[x];
}
if (flag && temp->is_leaf)
return true;
else
return false;
}
void remove(string &s) {
if (search(s))
root = remove(root, 0, s);
}
node *remove(node *root, int pos, string &s) {
if (pos <= s.length() - 1) {
(root->child)[s[pos]] = remove((root->child)[s[pos]], pos + 1, s);
bool flag = true;
for (int i = 0; i < L; i++)
if ((root->child)[i])
flag = false;
if (root->c != '#' && root->is_leaf == false && flag) {
delete (root);
root = nullptr;
}
} else {
root->is_leaf = false;
bool flag = true;
for (int i = 0; i < L; i++)
if ((root->child)[i])
flag = false;
if (flag) {
delete (root);
root = nullptr;
}
}
return root;
}
};
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int n, m;
cin >> n >> m;
if (n % 2 == 1) {
for (int i = 1; i <= m; i++)
cout << i << ' ' << n + 1 - i << '\n';
} else {
vector<bool> visited(n, false);
int j = 1, k = 2;
for (int i = 1; i <= m; i++) {
cout << j << ' ' << k << '\n';
visited[j] = true;
visited[k] = true;
if (i == m)
break;
k++;
if (k > n)
k -= n;
if (j > n)
j -= n;
while (visited[j] || visited[k]) {
j++;
k++;
if (k > n)
k -= n;
if (j > n)
j -= n;
}
}
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define R 1000000007
#define M 998244353
#define grid vector<vector<long long>>
#define L 256
long long mx = INT32_MIN, mn = INT32_MAX;
struct maths_util {
vector<long long> fact;
vector<bool> is_prime;
maths_util(int n = 200001, long long q = R) {
fact.resize(n);
is_prime.assign(n + 1, true);
fact[0] = 1;
for (int i = 1; i < n; i++)
fact[i] = (fact[i - 1] * i) % q;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++)
if (is_prime[i])
for (int j = i + i; j <= n; j += i)
is_prime[j] = false;
}
long long power_mod_q(long long x, long long n, long long q = R) {
if (n == 0)
return 1;
if (n % 2 == 0)
return power_mod_q((x * x) % q, n / 2, q);
else
return (x * power_mod_q((x * x) % q, n / 2, q)) % q;
}
long long inverse_mod_q(long long n, long long q = R) {
return power_mod_q(n, q - 2, q);
}
long long nCr_mod_q(long long n, long long r, long long q = R) {
return (((fact[n] * inverse_mod_q(fact[r], q)) % q) *
inverse_mod_q(fact[n - r], q)) %
q;
}
long long power(long long x, long long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return power(x * x, n / 2);
else
return x * power(x * x, n / 2);
}
grid multiply(grid &a, grid &b) {
int p = a.size(), q = b.size(), r = b[0].size();
grid c(p, vector<long long>(r, 0));
for (int i = 0; i < p; i++)
for (int j = 0; j < r; j++)
for (int k = 0; k < q; k++)
c[i][j] += a[i][k] * b[k][j];
return c;
}
grid add(grid &a, grid &b) {
int p = a.size(), q = a[0].size();
grid c(p, vector<long long>(q));
for (int i = 0; i < p; i++)
for (int j = 0; j < q; j++)
c[i][j] = a[i][j] + b[i][j];
return c;
}
grid power(grid &a, long long n) {
grid c(a.size(), vector<long long>(a.size(), 0));
if (n == 0) {
for (int i = 0; i < a.size(); i++)
c[i][i] = 1;
return c;
}
if (n % 2 == 0)
return power(c = multiply(a, a), n / 2);
else
return multiply(a, c = power(c = multiply(a, a), n / 2));
}
} u;
struct dsu {
vector<int> rank, parent, num;
dsu(int n) {
rank.assign(n, 0);
parent.resize(n);
for (int i = 0; i < n; i++)
parent[i] = i;
}
int find_set(int i) {
if (i == parent[i])
return i;
return parent[i] = find_set(parent[i]);
}
bool is_same_set(int i, int j) {
if (find_set(i) == find_set(j))
return true;
return false;
}
void union_set(int i, int j) {
if (!is_same_set(i, j)) {
int u = find_set(i), v = find_set(j);
if (rank[u] == rank[v]) {
parent[v] = u;
rank[u] += 1;
} else if (rank[u] > rank[v])
parent[v] = u;
else
parent[u] = v;
}
}
};
struct graph {
int v, time, count;
vector<pair<int, int>> *adj;
vector<bool> visited, in_stack, ap, in_MST;
stack<int> s;
vector<int> color, cc, d, f, l, finish_time, indegree, sccs, topo, outdegree,
pred, child;
graph(int n) {
v = n;
adj = new vector<pair<int, int>>[n];
visited.assign(n, false);
in_stack.assign(n, false);
ap.assign(n, false);
color.assign(n, 0);
cc.assign(n, -1);
d.assign(n, -1);
f.assign(n, -1);
indegree.assign(n, 0);
outdegree.assign(n, 0);
pred.assign(n, -1);
child.assign(n, 0);
time = count = 0;
finish_time.assign(2 * n, -1);
l.assign(n, 0);
}
void add_edge(int u, int v, int w) {
adj[u].push_back(make_pair(v, w));
adj[v].push_back(make_pair(u, w));
}
void dfs() {
color.assign(v, 0);
cc.assign(v, -1);
time = count = 0;
finish_time.assign(2 * v, -1);
visited.assign(v, false);
pred.assign(v, -1);
for (int i = 0; i < v; i++) {
if (color[i] == 0) {
dfs(i);
count++;
}
}
for (int i = 0; i < v; i++)
finish_time[f[i]] = i;
}
void dfs(int i) {
color[i] = 1;
cc[i] = count;
d[i] = time;
time++;
for (auto x : adj[i]) {
if (color[x.first] == 0) {
pred[x.first] = i;
dfs(x.first);
}
}
color[i] = 2;
f[i] = time;
time++;
}
void scc() {
graph g_t(v);
for (int i = 0; i < v; i++)
for (auto x : adj[i])
g_t.add_edge(x.first, i, x.second);
dfs();
for (int i = 2 * v - 1; i >= 0; i--) {
if (finish_time[i] != -1 && g_t.color[finish_time[i]] == 0) {
g_t.dfs(finish_time[i]);
g_t.count++;
}
}
sccs = g_t.cc;
count = g_t.count;
}
void topological_sort() {
for (int i = 0; i < v; i++)
if (adj[i].size())
outdegree[i] = adj[i].size();
for (int i = 0; i < v; i++)
for (auto x : adj[i])
indegree[x.first]++;
vector<int> zero;
for (int i = 0; i < v; i++)
if (!indegree[i])
zero.push_back(i);
while (!zero.empty()) {
int v = zero.back();
topo.push_back(v);
zero.pop_back();
for (auto x : adj[v]) {
indegree[x.first]--;
if (!indegree[x.first])
zero.push_back(x.first);
}
}
}
void tarjan() {
for (int i = 0; i < v; i++)
if (!color[i])
tarjan(i);
}
void tarjan(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
s.push(i);
in_stack[i] = true;
for (auto x : adj[i]) {
if (!color[x.first]) {
tarjan(x.first);
l[i] = min(l[i], l[x.first]);
} else if (in_stack[x.first]) {
l[i] = min(l[i], d[x.first]);
}
}
color[i] = 2;
f[i] = time;
time++;
if (d[i] == l[i]) {
while (s.top() != i)
cout << s.top() << ' ', in_stack[s.top()] = false, s.pop();
cout << s.top() << '\n', in_stack[s.top()] = false, s.pop();
}
}
// incomplete --->
void articulate() {
ap.assign(v, false);
color.assign(v, 0);
child.assign(v, 0);
time = 0;
d.assign(v, -1);
f.assign(v, -1);
l.assign(v, 0);
pred.assign(v, -1);
for (int i = 0; i < v; i++)
if (color[i] == 0) {
articulate(i);
if (child[i] == 1 || child[i] == 0)
ap[i] = false;
}
}
void articulate(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
for (auto x : adj[i]) {
if (pred[i] != x.first && color[x.first] == 1)
l[i] = min(l[i], d[x.first]);
if (!color[x.first]) {
pred[x.first] = i;
child[i]++;
articulate(x.first);
l[i] = min(l[i], l[x.first]);
}
if (l[x.first] >= d[i])
ap[i] = true;
}
f[i] = time;
time++;
color[i] = 2;
}
// incomplete --->
void bridges() {
time = 0;
f.assign(v, -1);
d.assign(v, -1);
l.assign(v, 0);
color.assign(v, 0);
pred.assign(v, -1);
for (int i = 0; i < v; i++)
if (color[i] == 0)
bridge(i);
}
void bridge(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
for (auto itr = adj[i].begin(); itr != adj[i].end(); itr++) {
if (pred[i] != itr->first && color[itr->first] == 1)
l[i] = min(l[i], d[itr->first]);
if (!color[itr->first]) {
pred[itr->first] = i;
bridge(itr->first);
l[i] = min(l[i], l[itr->first]);
}
if (l[itr->first] > d[i])
itr->second = 1;
}
color[i] = 2;
f[i] = time;
time++;
}
graph kruskal() {
vector<pair<int, pair<int, int>>> edges;
for (int i = 0; i < v; i++)
for (auto x : adj[i])
edges.push_back(make_pair(x.second, make_pair(i, x.first)));
sort(edges.begin(), edges.end());
dsu d(v);
graph mst(v);
for (auto x : edges) {
if (!d.is_same_set(x.second.first, x.second.second)) {
mst.add_edge(x.second.first, x.second.second, x.first);
d.union_set(x.second.first, x.second.second);
}
}
return mst;
}
graph prims(int s) {
priority_queue<pair<int, int>, vector<pair<int, int>>,
greater<pair<int, int>>>
pq;
d.assign(v, INT32_MAX);
pred.assign(v, -1);
in_MST.assign(v, false);
count = 0;
d[s] = 0;
pq.push({0, s});
while (count < v) {
int u = pq.top().second;
if (!in_MST[u])
in_MST[u] = true, count++;
pq.pop();
for (auto x : adj[u]) {
if (!in_MST[x.first] && d[x.first] > x.second) {
pq.push({x.second, x.first});
pred[x.first] = u;
d[x.first] = x.second;
}
}
}
graph mst(v);
for (int i = 0; i < v; i++) {
if (pred[i] != -1)
mst.add_edge(i, pred[i], d[i]);
}
return mst;
}
};
struct kmp {
vector<int> lps;
string p, t;
kmp(string &p, string &t) {
this->p = p;
this->t = t;
// PREPROCESSING
lps.assign(p.size(), 0);
lps[0] = 0;
int len = 0, i = 1, j;
while (i < p.size()) {
if (p[i] == p[len])
lps[i++] = ++len;
else if (len)
len = lps[len - 1];
else
lps[i++] = 0;
}
// STRING MATCHING
i = j = 0;
while (i < t.size()) {
if (p[j] == t[i])
j++, i++;
if (j == p.size()) {
// It's a match at index i - 1
j = lps[j - 1];
} else if (i < t.size() && p[j] != t[i]) {
if (j)
j = lps[j - 1];
else
i++;
}
}
}
};
// Pending lazy --->
struct segment_tree {
int n;
vector<int> a, tree;
segment_tree(vector<int> &a) {
this->n = a.size();
this->a = a;
tree.resize(4 * n);
build(0, 0, n - 1);
}
void build(int node, int l, int r) {
if (l == r)
tree[node] = a[r];
else {
int mid = (l + r) / 2;
build(2 * node + 1, l, mid);
build(2 * node + 2, mid + 1, r);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
}
void update(int node, int l, int r, int i, int x) {
if (l == r)
tree[node] = a[i] = x;
else {
int mid = (l + r) / 2;
if (i <= mid && i >= l)
update(2 * node + 1, l, mid, i, x);
else
update(2 * node + 2, mid + 1, r, i, x);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
}
int query(int node, int l, int r, int ql, int qr) {
if (l == ql && r == qr)
return tree[node];
else {
int mid = (l + r) / 2;
if (qr <= mid)
return query(2 * node + 1, l, mid, ql, qr);
else if (ql > mid)
return query(2 * node + 2, mid + 1, r, ql, qr);
else
return query(2 * node + 1, l, mid, ql, mid) +
query(2 * node + 2, mid + 1, r, mid + 1, qr);
}
}
};
struct trie {
struct node {
char c;
bool is_leaf;
vector<node *> child;
node(char ch) {
c = ch;
is_leaf = false;
child.assign(L, nullptr);
}
};
node *root;
trie() { root = new node('#'); }
void insert(string &s) {
node *temp = root;
for (auto x : s) {
if (!(temp->child)[x])
(temp->child)[x] = new node(x);
temp = (temp->child)[x];
}
temp->is_leaf = true;
}
bool has_child(node *temp) {
for (auto x : temp->child)
if (x)
return true;
return false;
}
bool search(string &s) {
node *temp = root;
bool flag = true;
for (auto x : s) {
if (!(temp->child)[x]) {
flag = false;
break;
}
temp = (temp->child)[x];
}
if (flag && temp->is_leaf)
return true;
else
return false;
}
void remove(string &s) {
if (search(s))
root = remove(root, 0, s);
}
node *remove(node *root, int pos, string &s) {
if (pos <= s.length() - 1) {
(root->child)[s[pos]] = remove((root->child)[s[pos]], pos + 1, s);
bool flag = true;
for (int i = 0; i < L; i++)
if ((root->child)[i])
flag = false;
if (root->c != '#' && root->is_leaf == false && flag) {
delete (root);
root = nullptr;
}
} else {
root->is_leaf = false;
bool flag = true;
for (int i = 0; i < L; i++)
if ((root->child)[i])
flag = false;
if (flag) {
delete (root);
root = nullptr;
}
}
return root;
}
};
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int n, m;
cin >> n >> m;
if (n % 2 == 1) {
for (int i = 1; i <= m; i++)
cout << i << ' ' << n + 1 - i << '\n';
} else {
int m2 = m / 2;
int m1 = m - m2;
for (int i = 1; i <= m1; ++i) {
cout << i << " " << m1 * 2 + 1 - i << '\n';
}
int d = m1 * 2;
for (int i = 1; i <= m2; ++i) {
cout << d + i << " " << d + m2 * 2 + 2 - i << '\n';
}
}
return 0;
}
| replace | 566 | 587 | 566 | 575 | TLE | |
p02697 | C++ | Runtime Error | /*
Author:Raghav Bansal
IIIT Una
*/
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define BOLT \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<array<int, 2>> ans;
if (n & 1) {
int a = 1, b = n / 2;
while (a < b) {
ans.pb({a, b});
a++;
b--;
}
a = n / 2 + 1, b = n - 1;
while (a < b) {
ans.pb({a, b});
a++;
b--;
}
} else {
int a = 1, b = n;
while (a < b) {
ans.pb({a, b});
a++;
b--;
}
}
for (int i = 0; i < m; i++) {
cout << ans[i][0] << " " << ans[i][1] << endl;
}
}
int32_t main() {
BOLT;
solve();
} | /*
Author:Raghav Bansal
IIIT Una
*/
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define BOLT \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<array<int, 2>> ans;
if ((n & 1) ^ 1) {
int a = 1, b = n / 2;
while (a < b) {
ans.pb({a, b});
a++;
b--;
}
a = n / 2 + 1, b = n - 1;
while (a < b) {
ans.pb({a, b});
a++;
b--;
}
} else {
int a = 1, b = n;
while (a < b) {
ans.pb({a, b});
a++;
b--;
}
}
for (int i = 0; i < m; i++) {
cout << ans[i][0] << " " << ans[i][1] << endl;
}
}
int32_t main() {
BOLT;
solve();
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int i = 1, j = (N + 1) / 2;
int D = j - i - 1;
vector<pair<int, int>> ans;
while (i < j)
ans.emplace_back(i++, j--);
i = N - D, j = N;
while (ans.size() < M)
ans.emplace_back(i++, j--);
assert(ans.size() == M);
for (auto &[a, b] : ans)
cout << a << " " << b << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int i = 1, j = (N + 1) / 2;
int D = j - i - 1;
vector<pair<int, int>> ans;
while (i < j)
ans.emplace_back(i++, j--);
i = N - D, j = N;
while (ans.size() < M)
ans.emplace_back(i++, j--);
while (ans.size() > M)
ans.pop_back();
assert(ans.size() == M);
for (auto &[a, b] : ans)
cout << a << " " << b << '\n';
return 0;
}
| insert | 14 | 14 | 14 | 16 | 0 | |
p02697 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int u[100005];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, k;
cin >> n >> k;
if (n % 2 == 1) {
for (int j = 1; j <= k; j++) {
cout << j << " " << (2 * k + 1 - j) << endl;
}
} else {
for (int i = k; i >= 1; i--) {
for (int j = 1; j <= n; j++)
if (!u[j] && !u[(j + i - 1) % n + 1]) {
cout << j << " " << (j + i - 1) % n + 1 << endl;
u[j] = 1;
u[(j + i - 1) % n + 1] = 1;
break;
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int u[100005];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, k;
cin >> n >> k;
if (n % 2 == 1) {
for (int j = 1; j <= k; j++) {
cout << j << " " << (2 * k + 1 - j) << endl;
}
} else {
int mx = 0;
for (int j = 1, dist = k; dist > 0; j++, dist -= 2) {
cout << j << " " << j + dist << endl;
mx = max(mx, j + dist);
}
for (int j = mx + 1, dist = k - 1; dist > 0; j++, dist -= 2) {
cout << j << " " << j + dist << endl;
}
}
}
| replace | 23 | 31 | 23 | 30 | 0 | |
p02697 | Python | Runtime Error | n, m = map(int, input().split())
if n % 2 == 1:
for i in range(1, m + 1):
print(i, n + 1 - i)
else:
used = [False] * (n + 1)
i = 1
count = 0
while count < m:
while used[i]:
i += 1
print(i, i + count + 1)
used[i] = True
used[i + count + 1] = True
count += 1
| n, m = map(int, input().split())
if n % 2 == 1:
for i in range(1, m + 1):
print(i, n + 1 - i)
else:
turning_point = (m + 1) // 2
for i in range(1, turning_point + 1):
print(i, n + 1 - i)
for i in range(turning_point + 1, m + 1):
print(i, n - i)
| replace | 5 | 15 | 5 | 10 | 0 | |
p02697 | Python | Runtime Error | import sys
sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N, M = map(int, input().split())
if N % 2 == 0:
used = [False] * (N + 1)
i = 0
span = 1
cnt = 0
while cnt < M:
cnt += 1
while used[i]:
i += 1
print(i + 1, i + 1 + span)
used[i] = True
used[i + span] = True
span += 1
else:
for i in range(M):
print(i + 1, N - i)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N, M = map(int, input().split())
if N % 2 == 0:
for i in range(M):
x = i + 1
y = N - i - 1
if y - x > (N - y + x):
print(x, y)
else:
print(x, y - 1)
else:
for i in range(M):
print(i + 1, N - i)
if __name__ == "__main__":
main()
| replace | 16 | 28 | 16 | 23 | 0 | |
p02698 | C++ | Runtime Error | /*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// here!!!
// define int long long !!!!!
#define int long long
// define int long long !!!!!
#define mod 1000000007ll
// constexpr int mod = 998244353ll;
constexpr double PI = 3.141592653589793238462643383279;
// constexpr double eps = DBL_EPSILON;
typedef long long ll;
#ifdef int
#define inf (int)(3e18)
#else
#define inf (int)(5e8)
#endif
#define intt long long
#define itn long long
#define innt long long
#define P pair<long long, long long>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define rev_rep(i, n) for (int i = n - 1; i >= 0; i--)
#define REV_REP(i, n) for (int i = n; i >= 1; i--)
#define ALL(v) v.begin(), v.end()
#define smallpriority_queue(T) priority_queue<T, vector<T>, greater<T>>
using namespace std;
// Library
// モッドパウ
inline int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y & 1) {
res *= x;
res %= m;
}
x = x * x % m;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
// is the number (x) a prime number?
// bool prime(int x) {
// if (!x || x == 1) {
// return false;
// }
// for (int i = 2; i * i <= x; i++) {
// if (!(x % i)) {
// return false;
// }
// }
// return true;
// }
bool prime(int x) {
if (!x || x == 1) {
return false;
}
if (x == 2) {
return true;
}
if (!(x & 1)) {
return false;
}
for (int i = 3; i * i <= x; i += 2) {
if (!(x % i)) {
return false;
}
}
return true;
}
// saidai-kouyakusuu
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// number of keta
int keta(int x) {
int ans = 0;
while (x) {
x /= 10;
ans++;
}
return ans;
}
// number of 2shinsuu keta
int bitketa(int x) {
int ans = 0;
while (x) {
x >>= 1;
ans++;
}
return ans;
}
// sum of keta
int ketasum(int x) {
int ans = 0;
while (x) {
ans += x % 10;
x /= 10;
}
return ans;
}
inline int lcm(int x, int y) {
int ans = x / gcd(x, y) * y;
return ans;
}
int twobeki(int x) {
int ans = 0;
while (1) {
if (!(x & 1)) {
ans++;
x >>= 1;
} else {
break;
}
}
return ans;
}
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
#define fin(i) scanf("%lld", &i)
#define fout(i) printf("%lld", i)
#define fendl printf("\n")
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
// cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl;
return kai(x, y) * modpow(kai(y, y), mod - 2) % mod;
}
// Library-End
// 入出力高速化時にはoff!!!!
// #define vecin(v) for(int i=0;i<v.size();i++)scanf("%lld",&v[i]);
// #define vecout(v) {if(v.size())printf("%lld",v[0]);for(int
// i=1;i<(int)v.size();i++)printf(" %lld",v[i]);printf("\n");}
template <class T> class SegTree {
int n;
vector<T> node;
T def;
function<T(T, T)> operation;
function<T(T, T)> update;
public:
SegTree(unsigned int _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
node = vector<T>(n * 2, def);
}
SegTree(vector<int> &initvec, function<T(T, T)> _operation,
function<T(T, T)> _update)
: operation(_operation), update(_update) {
n = 1;
while (n < initvec.size()) {
n *= 2;
}
node = vector<T>(n * 2, def);
for (int i = n; i < n + initvec.size(); i++) {
node[i] = initvec[i - n];
}
for (int i = n - 1; i >= 1; i--) {
node[i] = operation(node[i * 2], node[i * 2 + 1]);
}
}
void change(int i, T x) {
i += n;
node[i] = update(node[i], x);
while (i >= 1) {
i >>= 1;
node[i] = operation(node[i * 2], node[i * 2 + 1]);
}
}
T query(int l, int r) {
l += n;
r += n;
T rx = def, lx = def;
while (l < r) {
if (l & 1) {
lx = operation(lx, node[l]);
l++;
}
if (r & 1) {
r--;
rx = operation(node[r], rx);
}
l >>= 1;
r >>= 1;
}
return operation(lx, rx);
}
T operator[](const int &x) { return node[x + n]; }
void fill(T x) { std::fill(ALL(node), x); }
void print() {
rep(i, n) std::cout << operator[](i) << " ";
std::cout << std::endl;
}
T queryForALL() { return node[1]; }
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
class Union_Find {
vector<int> par;
vector<int> ookisa;
public:
Union_Find(int size) {
par = vector<int>(size);
ookisa = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
ookisa[i] = 1;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (ookisa[x] < ookisa[y]) {
par[x] = y;
ookisa[y] += ookisa[x];
ookisa[x] = 0;
} else {
par[y] = x;
ookisa[x] += ookisa[y];
ookisa[y] = 0;
}
}
int size(int i) {
i = find(i);
return ookisa[i];
}
bool same(int x, int y) { return find(x) == find(y); }
};
class BIT {
vector<int> data;
int size = 0;
public:
BIT(int _size) {
data = vector<int>(_size + 1);
size = _size;
}
void add(int i, int x) {
while (i <= size) {
data[i] += x;
i += i & -i;
}
}
int sum(int i) {
assert(i <= size);
int s = 0;
while (i > 0) {
s += data[i];
i -= i & -i;
}
return s;
}
int lower_bound(int x) {
if (x <= 0) {
return 0;
} else {
int i = 0;
int r = 1;
while (r < size)
r = r << 1;
for (int len = r; len > 0; len = len >> 1) {
if (i + len < size && data[i + len] < x) {
x -= data[i + len];
i += len;
}
}
return i + 1;
}
}
};
// Union-Find-End
int perm[2000005];
void init_perm() {
perm[0] = 1;
REP(i, 2000004) { perm[i] = perm[i - 1] * i % mod; }
}
int nCk(int x, int y) {
if (y > x) {
return 0;
}
if (x < 0) {
return 0;
}
return perm[x] * modpow(perm[x - y], mod - 2) % mod *
modpow(perm[y], mod - 2) % mod;
}
struct Dot {
double x;
double y;
Dot(double _x = 0.0, double _y = 0.0) {
x = _x;
y = _y;
}
};
struct Dot_i {
int x;
int y;
Dot_i(int _x = 0, int _y = 0) {
x = _x;
y = _y;
}
};
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
double kyori(Dot f, Dot s) {
double ans = 0;
double t = fabs(f.x - s.x);
double y = fabs(f.y - s.y);
ans = sqrt(t * t + y * y);
return ans;
}
inline string stringmax(string &x, string &y) {
if (x.size() > y.size()) {
return x;
}
if (x.size() < y.size()) {
return y;
}
rep(i, x.size()) {
if (x[i] > y[i]) {
return x;
}
if (x[i] < y[i]) {
return y;
}
}
return x;
}
// vector<int> RollingHash(string &s, string& t){
// vector<int> ans;
// if(s.size()<t.size())return ans;
// __int128 h=0,hamod=0,ki=0,kim=0,hikaku=0,one=0;
// one=1;
// ki=1000000007ll;
// hamod=(one<<61)-1;
// kim=1;
// rep(i,t.size()){
// hikaku*=ki;
// h*=ki;
// kim*=ki;
// hikaku+=t[i];
// h+=s[i];
// hikaku%=hamod;
// h%=hamod;
// kim%=hamod;
// }
// rep(i,(int)s.size()-(int)t.size()){
// if (h==hikaku) {
// ans.emplace_back(i);
// }
// h*=ki;
// h%=hamod;
// h+=s[i+(int)t.size()];
// h%=hamod;
// h+=hamod;
// h-=s[i]*kim%hamod;
// h%=hamod;
// }
// if(h==hikaku)ans.emplace_back((int)s.size()-(int)t.size());
// return ans;
// }
struct edge {
int to;
int length;
edge(int _to, int _length) {
to = _to;
length = _length;
}
};
vector<int> djkstra(vector<vector<edge>> &road, int start) {
vector<int> kyo(road.size(), inf);
smallpriority_queue(P) q;
q.push({0, start});
kyo[start] = 0;
while (q.size()) {
int x = q.top().second;
itn now = q.top().first;
q.pop();
if (kyo[x] < now) {
continue;
}
for (auto &i : road[x]) {
if (kyo[i.to] > now + i.length) {
kyo[i.to] = now + i.length;
q.push({kyo[i.to], i.to});
}
}
}
return kyo;
}
template <class T> void change_to_unique(vector<T> &v) {
std::sort(ALL(v));
auto k = unique(ALL(v));
if (k != v.end())
v.erase(k, v.end());
}
double kodo_dosuu(double r) { return 180.0 * r / (double)PI; }
double dosuu_kodo(double r) { return r * (double)PI / 180.0; }
double kakudo(Dot a, Dot b1, Dot b2) {
double size1 = kyori(a, b1), size2 = kyori(a, b2);
double nai = (b1.x - a.x) * (b2.x - a.x) + (b1.y - a.y) * (b2.y - a.y);
nai /= size1 * size2;
return kodo_dosuu(acos(nai));
}
struct fraction {
int shi;
int bo;
fraction(int bunshi, int bunbo) : bo(bunbo), shi(bunshi) {
if (bunbo && bunshi) {
int g = gcd(bo, shi);
bo /= g;
shi /= g;
}
};
explicit inline operator double() const { return (double)shi / (double)bo; }
explicit inline operator long double() const {
return (long double)shi / (long double)bo;
}
};
bool operator<(const fraction &b1, const fraction &b2) {
return b1.shi * b2.bo < b2.shi * b1.bo;
}
bool operator>(const fraction &b1, const fraction &b2) {
return b1.shi * b2.bo > b2.shi * b1.bo;
}
template <class T> void vecout(vector<T> &v) {
if (v.size()) {
cout << v[0];
}
REP(i, (int)v.size() - 1) { cout << ' ' << v[i]; }
cout << endl;
}
inline int zeronCk(int x, int y) { return nCk(y + x - 1, x - 1); }
inline int modinv(int x, int MOD = mod) { return modpow(x, MOD - 2); }
#define endl "\n" // interactive の時に注意!!!
#define Endl "\n" // interactive の時に注意!!!
#define cinn cin
#define printd cout << fixed << setprecision(10)
#define rrep(i, f, s) for (int i = f; i < s; i++)
#define RREP(i, f, s) for (int i = f; i <= s; i++)
#define REV_RREP(i, f, s) for (int i = s; i >= f; i--)
#define hen_rep(i, l, step) for (int i = 0; i < l; i += step)
#define HEN_REP(i, l, step) for (int i = 1; i <= l; i += step)
int n, a[200004], u, v, ans[200004];
vector<int> road[20004];
vector<int> now;
void dfs(itn x, int par) {
auto k = lower_bound(ALL(now), a[x]);
int basho = k - now.begin();
bool did = k == now.end();
int p = (did ? 0 : (*k));
if (basho == now.size()) {
now.emplace_back(a[x]);
} else {
now[basho] = a[x];
}
ans[x] = now.size();
for (auto &i : road[x]) {
if (i == par) {
continue;
}
dfs(i, x);
}
if (did) {
now.pop_back();
} else {
now[basho] = p;
}
}
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n;
REP(i, n) { cin >> a[i]; }
rep(i, n - 1) {
cin >> u >> v;
road[u].emplace_back(v);
road[v].emplace_back(u);
}
dfs(1, 1);
REP(i, n) { cout << ans[i] << endl; }
}
| /*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// here!!!
// define int long long !!!!!
#define int long long
// define int long long !!!!!
#define mod 1000000007ll
// constexpr int mod = 998244353ll;
constexpr double PI = 3.141592653589793238462643383279;
// constexpr double eps = DBL_EPSILON;
typedef long long ll;
#ifdef int
#define inf (int)(3e18)
#else
#define inf (int)(5e8)
#endif
#define intt long long
#define itn long long
#define innt long long
#define P pair<long long, long long>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define rev_rep(i, n) for (int i = n - 1; i >= 0; i--)
#define REV_REP(i, n) for (int i = n; i >= 1; i--)
#define ALL(v) v.begin(), v.end()
#define smallpriority_queue(T) priority_queue<T, vector<T>, greater<T>>
using namespace std;
// Library
// モッドパウ
inline int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y & 1) {
res *= x;
res %= m;
}
x = x * x % m;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
// is the number (x) a prime number?
// bool prime(int x) {
// if (!x || x == 1) {
// return false;
// }
// for (int i = 2; i * i <= x; i++) {
// if (!(x % i)) {
// return false;
// }
// }
// return true;
// }
bool prime(int x) {
if (!x || x == 1) {
return false;
}
if (x == 2) {
return true;
}
if (!(x & 1)) {
return false;
}
for (int i = 3; i * i <= x; i += 2) {
if (!(x % i)) {
return false;
}
}
return true;
}
// saidai-kouyakusuu
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// number of keta
int keta(int x) {
int ans = 0;
while (x) {
x /= 10;
ans++;
}
return ans;
}
// number of 2shinsuu keta
int bitketa(int x) {
int ans = 0;
while (x) {
x >>= 1;
ans++;
}
return ans;
}
// sum of keta
int ketasum(int x) {
int ans = 0;
while (x) {
ans += x % 10;
x /= 10;
}
return ans;
}
inline int lcm(int x, int y) {
int ans = x / gcd(x, y) * y;
return ans;
}
int twobeki(int x) {
int ans = 0;
while (1) {
if (!(x & 1)) {
ans++;
x >>= 1;
} else {
break;
}
}
return ans;
}
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
#define fin(i) scanf("%lld", &i)
#define fout(i) printf("%lld", i)
#define fendl printf("\n")
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
// cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl;
return kai(x, y) * modpow(kai(y, y), mod - 2) % mod;
}
// Library-End
// 入出力高速化時にはoff!!!!
// #define vecin(v) for(int i=0;i<v.size();i++)scanf("%lld",&v[i]);
// #define vecout(v) {if(v.size())printf("%lld",v[0]);for(int
// i=1;i<(int)v.size();i++)printf(" %lld",v[i]);printf("\n");}
template <class T> class SegTree {
int n;
vector<T> node;
T def;
function<T(T, T)> operation;
function<T(T, T)> update;
public:
SegTree(unsigned int _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
node = vector<T>(n * 2, def);
}
SegTree(vector<int> &initvec, function<T(T, T)> _operation,
function<T(T, T)> _update)
: operation(_operation), update(_update) {
n = 1;
while (n < initvec.size()) {
n *= 2;
}
node = vector<T>(n * 2, def);
for (int i = n; i < n + initvec.size(); i++) {
node[i] = initvec[i - n];
}
for (int i = n - 1; i >= 1; i--) {
node[i] = operation(node[i * 2], node[i * 2 + 1]);
}
}
void change(int i, T x) {
i += n;
node[i] = update(node[i], x);
while (i >= 1) {
i >>= 1;
node[i] = operation(node[i * 2], node[i * 2 + 1]);
}
}
T query(int l, int r) {
l += n;
r += n;
T rx = def, lx = def;
while (l < r) {
if (l & 1) {
lx = operation(lx, node[l]);
l++;
}
if (r & 1) {
r--;
rx = operation(node[r], rx);
}
l >>= 1;
r >>= 1;
}
return operation(lx, rx);
}
T operator[](const int &x) { return node[x + n]; }
void fill(T x) { std::fill(ALL(node), x); }
void print() {
rep(i, n) std::cout << operator[](i) << " ";
std::cout << std::endl;
}
T queryForALL() { return node[1]; }
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
class Union_Find {
vector<int> par;
vector<int> ookisa;
public:
Union_Find(int size) {
par = vector<int>(size);
ookisa = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
ookisa[i] = 1;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (ookisa[x] < ookisa[y]) {
par[x] = y;
ookisa[y] += ookisa[x];
ookisa[x] = 0;
} else {
par[y] = x;
ookisa[x] += ookisa[y];
ookisa[y] = 0;
}
}
int size(int i) {
i = find(i);
return ookisa[i];
}
bool same(int x, int y) { return find(x) == find(y); }
};
class BIT {
vector<int> data;
int size = 0;
public:
BIT(int _size) {
data = vector<int>(_size + 1);
size = _size;
}
void add(int i, int x) {
while (i <= size) {
data[i] += x;
i += i & -i;
}
}
int sum(int i) {
assert(i <= size);
int s = 0;
while (i > 0) {
s += data[i];
i -= i & -i;
}
return s;
}
int lower_bound(int x) {
if (x <= 0) {
return 0;
} else {
int i = 0;
int r = 1;
while (r < size)
r = r << 1;
for (int len = r; len > 0; len = len >> 1) {
if (i + len < size && data[i + len] < x) {
x -= data[i + len];
i += len;
}
}
return i + 1;
}
}
};
// Union-Find-End
int perm[2000005];
void init_perm() {
perm[0] = 1;
REP(i, 2000004) { perm[i] = perm[i - 1] * i % mod; }
}
int nCk(int x, int y) {
if (y > x) {
return 0;
}
if (x < 0) {
return 0;
}
return perm[x] * modpow(perm[x - y], mod - 2) % mod *
modpow(perm[y], mod - 2) % mod;
}
struct Dot {
double x;
double y;
Dot(double _x = 0.0, double _y = 0.0) {
x = _x;
y = _y;
}
};
struct Dot_i {
int x;
int y;
Dot_i(int _x = 0, int _y = 0) {
x = _x;
y = _y;
}
};
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
double kyori(Dot f, Dot s) {
double ans = 0;
double t = fabs(f.x - s.x);
double y = fabs(f.y - s.y);
ans = sqrt(t * t + y * y);
return ans;
}
inline string stringmax(string &x, string &y) {
if (x.size() > y.size()) {
return x;
}
if (x.size() < y.size()) {
return y;
}
rep(i, x.size()) {
if (x[i] > y[i]) {
return x;
}
if (x[i] < y[i]) {
return y;
}
}
return x;
}
// vector<int> RollingHash(string &s, string& t){
// vector<int> ans;
// if(s.size()<t.size())return ans;
// __int128 h=0,hamod=0,ki=0,kim=0,hikaku=0,one=0;
// one=1;
// ki=1000000007ll;
// hamod=(one<<61)-1;
// kim=1;
// rep(i,t.size()){
// hikaku*=ki;
// h*=ki;
// kim*=ki;
// hikaku+=t[i];
// h+=s[i];
// hikaku%=hamod;
// h%=hamod;
// kim%=hamod;
// }
// rep(i,(int)s.size()-(int)t.size()){
// if (h==hikaku) {
// ans.emplace_back(i);
// }
// h*=ki;
// h%=hamod;
// h+=s[i+(int)t.size()];
// h%=hamod;
// h+=hamod;
// h-=s[i]*kim%hamod;
// h%=hamod;
// }
// if(h==hikaku)ans.emplace_back((int)s.size()-(int)t.size());
// return ans;
// }
struct edge {
int to;
int length;
edge(int _to, int _length) {
to = _to;
length = _length;
}
};
vector<int> djkstra(vector<vector<edge>> &road, int start) {
vector<int> kyo(road.size(), inf);
smallpriority_queue(P) q;
q.push({0, start});
kyo[start] = 0;
while (q.size()) {
int x = q.top().second;
itn now = q.top().first;
q.pop();
if (kyo[x] < now) {
continue;
}
for (auto &i : road[x]) {
if (kyo[i.to] > now + i.length) {
kyo[i.to] = now + i.length;
q.push({kyo[i.to], i.to});
}
}
}
return kyo;
}
template <class T> void change_to_unique(vector<T> &v) {
std::sort(ALL(v));
auto k = unique(ALL(v));
if (k != v.end())
v.erase(k, v.end());
}
double kodo_dosuu(double r) { return 180.0 * r / (double)PI; }
double dosuu_kodo(double r) { return r * (double)PI / 180.0; }
double kakudo(Dot a, Dot b1, Dot b2) {
double size1 = kyori(a, b1), size2 = kyori(a, b2);
double nai = (b1.x - a.x) * (b2.x - a.x) + (b1.y - a.y) * (b2.y - a.y);
nai /= size1 * size2;
return kodo_dosuu(acos(nai));
}
struct fraction {
int shi;
int bo;
fraction(int bunshi, int bunbo) : bo(bunbo), shi(bunshi) {
if (bunbo && bunshi) {
int g = gcd(bo, shi);
bo /= g;
shi /= g;
}
};
explicit inline operator double() const { return (double)shi / (double)bo; }
explicit inline operator long double() const {
return (long double)shi / (long double)bo;
}
};
bool operator<(const fraction &b1, const fraction &b2) {
return b1.shi * b2.bo < b2.shi * b1.bo;
}
bool operator>(const fraction &b1, const fraction &b2) {
return b1.shi * b2.bo > b2.shi * b1.bo;
}
template <class T> void vecout(vector<T> &v) {
if (v.size()) {
cout << v[0];
}
REP(i, (int)v.size() - 1) { cout << ' ' << v[i]; }
cout << endl;
}
inline int zeronCk(int x, int y) { return nCk(y + x - 1, x - 1); }
inline int modinv(int x, int MOD = mod) { return modpow(x, MOD - 2); }
#define endl "\n" // interactive の時に注意!!!
#define Endl "\n" // interactive の時に注意!!!
#define cinn cin
#define printd cout << fixed << setprecision(10)
#define rrep(i, f, s) for (int i = f; i < s; i++)
#define RREP(i, f, s) for (int i = f; i <= s; i++)
#define REV_RREP(i, f, s) for (int i = s; i >= f; i--)
#define hen_rep(i, l, step) for (int i = 0; i < l; i += step)
#define HEN_REP(i, l, step) for (int i = 1; i <= l; i += step)
int n, a[200004], u, v, ans[200004];
vector<int> road[200004];
vector<int> now;
void dfs(itn x, int par) {
auto k = lower_bound(ALL(now), a[x]);
int basho = k - now.begin();
bool did = k == now.end();
int p = (did ? 0 : (*k));
if (basho == now.size()) {
now.emplace_back(a[x]);
} else {
now[basho] = a[x];
}
ans[x] = now.size();
for (auto &i : road[x]) {
if (i == par) {
continue;
}
dfs(i, x);
}
if (did) {
now.pop_back();
} else {
now[basho] = p;
}
}
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n;
REP(i, n) { cin >> a[i]; }
rep(i, n - 1) {
cin >> u >> v;
road[u].emplace_back(v);
road[v].emplace_back(u);
}
dfs(1, 1);
REP(i, n) { cout << ans[i] << endl; }
}
| replace | 590 | 591 | 590 | 591 | 0 | |
p02698 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define fio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(), (v).end()
#define sq(x) ((x) * (x))
#define foreach(it, v) for (auto it = (v).begin(); it != (v).end(); ++it)
#define tr(...) \
cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \
trace(#__VA_ARGS__, __VA_ARGS__)
#define tr(...) \
cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \
trace(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void trace(const char *name, T &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char *names, T &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
trace(comma + 1, args...);
}
typedef long double dbl;
bool codejam = 0;
const int MOD = 1000 * 1000 * 1000 + 7;
const int NMAX = 1000 * 1000 + 11;
int arr[NMAX];
int n, m, p, q, k, a, b, c;
char ch;
vector<int> v;
vector<int> gr[200011];
set<int> s;
int ans[NMAX];
void dfs(int cur, int par) {
s.insert(arr[cur]);
auto it = s.lower_bound(arr[cur]);
it++;
int del = -1;
if (it != s.end()) {
del = *it;
s.erase(it);
}
ans[cur] = s.size();
for (auto ch : gr[cur]) {
// cout<<ch<<" "<<cur<<" "<<par<<"\n";
if (ch != par) {
dfs(ch, cur);
}
}
if (del != -1)
s.insert(del);
s.erase(s.find(arr[cur]));
return;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
int u, v;
for (int i = 1; i <= n - 1; i++) {
cin >> u >> v;
gr[u].pb(v);
gr[v].pb(u);
}
dfs(1, 1);
for (int i = 1; i <= n; i++)
cout << ans[i] << "\n";
}
int32_t main() {
fio;
int t = 1;
int cs = 1;
// cin>>t;
while (t--) {
if (codejam) {
cout << "Case #" << cs << ": ";
}
cs++;
solve();
cout << "\n";
}
} | #include "bits/stdc++.h"
using namespace std;
#define fio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(), (v).end()
#define sq(x) ((x) * (x))
#define foreach(it, v) for (auto it = (v).begin(); it != (v).end(); ++it)
#define tr(...) \
cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \
trace(#__VA_ARGS__, __VA_ARGS__)
#define tr(...) \
cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \
trace(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void trace(const char *name, T &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char *names, T &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
trace(comma + 1, args...);
}
typedef long double dbl;
bool codejam = 0;
const int MOD = 1000 * 1000 * 1000 + 7;
const int NMAX = 1000 * 1000 + 11;
int arr[NMAX];
int n, m, p, q, k, a, b, c;
char ch;
vector<int> v;
vector<int> gr[200011];
multiset<int> s;
int ans[NMAX];
void dfs(int cur, int par) {
s.insert(arr[cur]);
auto it = s.lower_bound(arr[cur]);
it++;
int del = -1;
if (it != s.end()) {
del = *it;
s.erase(it);
}
ans[cur] = s.size();
for (auto ch : gr[cur]) {
// cout<<ch<<" "<<cur<<" "<<par<<"\n";
if (ch != par) {
dfs(ch, cur);
}
}
if (del != -1)
s.insert(del);
s.erase(s.find(arr[cur]));
return;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
int u, v;
for (int i = 1; i <= n - 1; i++) {
cin >> u >> v;
gr[u].pb(v);
gr[v].pb(u);
}
dfs(1, 1);
for (int i = 1; i <= n; i++)
cout << ans[i] << "\n";
}
int32_t main() {
fio;
int t = 1;
int cs = 1;
// cin>>t;
while (t--) {
if (codejam) {
cout << "Case #" << cs << ": ";
}
cs++;
solve();
cout << "\n";
}
} | replace | 49 | 50 | 49 | 50 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.