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
p02996
C++
Runtime Error
#include <bits/stdc++.h> #define LL long long #define MP make_pair #define PB push_back #define F first #define S second #define I insert #define bull bool #define Max(a, b) ((b < a) ? a : b) #define Min(a, b) ((a < b) ? a : b) const LL N = 100005, mod = 1000000007; using namespace std; LL n, m, i, j, k, l, r, t, ans; pair<LL, LL> p[N]; LL getint() { char c = getchar(); LL t = 0; while (!isdigit(c)) c = getchar(); while (isdigit(c)) { t = (t << 3) + (t << 1); t += c - '0'; c = getchar(); } return t; } int main() { /*/ freopen ( "detectivein.txt", "r", stdin); freopen ( "detectiveout.txt", "w", stdout); /**/ cin >> n; for (i = 0; i < n; ++i) { cin >> p[i].S >> p[i].F; } sort(p, p + n); k = 0; for (i = 0; i < n; ++i) { if (k + p[i].S > p[i].F) { cout << "No\n"; return 0; } k += p[i].S; } cout << "Yes\n"; return 0; } /**/ // IIIIIIIII OOOOO A NN N EEEEEEEEEE // I O O A A N N N E // I O O A A N N N E // I O O A A N N N E // I O O AAAAAAAAA N N N EEEEEEEE // I O O A A N N N E // I O O A A N N N E // I O O A A N N N E // IIIIIIIII OOOOO A A N NN EEEEEEEEEE // ___ KAPANADZE
#include <bits/stdc++.h> #define LL long long #define MP make_pair #define PB push_back #define F first #define S second #define I insert #define bull bool #define Max(a, b) ((b < a) ? a : b) #define Min(a, b) ((a < b) ? a : b) const LL N = 200005, mod = 1000000007; using namespace std; LL n, m, i, j, k, l, r, t, ans; pair<LL, LL> p[N]; LL getint() { char c = getchar(); LL t = 0; while (!isdigit(c)) c = getchar(); while (isdigit(c)) { t = (t << 3) + (t << 1); t += c - '0'; c = getchar(); } return t; } int main() { /*/ freopen ( "detectivein.txt", "r", stdin); freopen ( "detectiveout.txt", "w", stdout); /**/ cin >> n; for (i = 0; i < n; ++i) { cin >> p[i].S >> p[i].F; } sort(p, p + n); k = 0; for (i = 0; i < n; ++i) { if (k + p[i].S > p[i].F) { cout << "No\n"; return 0; } k += p[i].S; } cout << "Yes\n"; return 0; } /**/ // IIIIIIIII OOOOO A NN N EEEEEEEEEE // I O O A A N N N E // I O O A A N N N E // I O O A A N N N E // I O O AAAAAAAAA N N N EEEEEEEE // I O O A A N N N E // I O O A A N N N E // I O O A A N N N E // IIIIIIIII OOOOO A A N NN EEEEEEEEEE // ___ KAPANADZE
replace
11
12
11
12
0
p02996
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, s, n) for (int i = s; i < (n); ++i) #define sz(x) int(x.size()) typedef long long ll; using namespace std; /*******-c++14 don't include-*******/ template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } void printArr(int *a, int len) { for (int i = 0; i < len; i++) { if (i) cout << " "; cout << a[i]; } cout << endl; } /*******---------------------*******/ static const int INTINF = (2147483647); static const ll LLINF = (9223372036854775807); static const int MAX = 100001; static const ll MOD = 1000000007; //--global--// struct MyTask { ll a, b; MyTask() {} MyTask(ll a0, ll b0) : a(a0), b(b0) {} bool operator<(const MyTask &rhs) const { if (b < rhs.b) { return true; } return false; } }; //----------// int main(int argc, const char *argv[]) { // 提出時、消す----// //--------------// ll n; cin >> n; MyTask Tasks[MAX]; rep(i, n) { ll a; ll b; cin >> a; cin >> b; Tasks[i] = MyTask(a, b); } sort(Tasks, Tasks + n, [](const MyTask &x, const MyTask &y) { return x.a < y.a; }); sort(Tasks, Tasks + n); ll now = 0; rep(i, n) { now += Tasks[i].a; if (now > Tasks[i].b) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, s, n) for (int i = s; i < (n); ++i) #define sz(x) int(x.size()) typedef long long ll; using namespace std; /*******-c++14 don't include-*******/ template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } void printArr(int *a, int len) { for (int i = 0; i < len; i++) { if (i) cout << " "; cout << a[i]; } cout << endl; } /*******---------------------*******/ static const int INTINF = (2147483647); static const ll LLINF = (9223372036854775807); static const int MAX = 200001; static const ll MOD = 1000000007; //--global--// struct MyTask { ll a, b; MyTask() {} MyTask(ll a0, ll b0) : a(a0), b(b0) {} bool operator<(const MyTask &rhs) const { if (b < rhs.b) { return true; } return false; } }; //----------// int main(int argc, const char *argv[]) { // 提出時、消す----// //--------------// ll n; cin >> n; MyTask Tasks[MAX]; rep(i, n) { ll a; ll b; cin >> a; cin >> b; Tasks[i] = MyTask(a, b); } sort(Tasks, Tasks + n, [](const MyTask &x, const MyTask &y) { return x.a < y.a; }); sort(Tasks, Tasks + n); ll now = 0; rep(i, n) { now += Tasks[i].a; if (now > Tasks[i].b) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
replace
28
29
28
29
0
p02996
C++
Runtime Error
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; constexpr ll MOD = 1000000007; // struct UnionFind { // vector<int> par; // UnionFind(int N): par(N) { // for (int i=0;i<N;i++) par[i] = i; // } // int root(int x) { // if (par[x] == x) return x; // else return par[x] = root(par[x]); // } // void unite(int x, int y) { // int rx = root(x); // int ry = root(y); // if (rx == ry) return; // par[rx] = ry; // } // bool same(int x, int y) { // int rx = root(x); // int ry = root(y); // return rx == ry; // } // }; typedef struct { ll time, dead; } work; int workcmp(const void *a, const void *b) { if ((*(work *)a).dead < (*(work *)b).dead) return -1; else if ((*(work *)a).dead == (*(work *)b).dead) return 0; else return 1; } int main(void) { int N; work W[100010]; cin >> N; for (int i = 0; i < N; i++) cin >> W[i].time >> W[i].dead; qsort(W, N, sizeof(work), workcmp); ll C = 0; for (int i = 0; i < N; i++) { C += W[i].time; if (W[i].dead < C) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; constexpr ll MOD = 1000000007; // struct UnionFind { // vector<int> par; // UnionFind(int N): par(N) { // for (int i=0;i<N;i++) par[i] = i; // } // int root(int x) { // if (par[x] == x) return x; // else return par[x] = root(par[x]); // } // void unite(int x, int y) { // int rx = root(x); // int ry = root(y); // if (rx == ry) return; // par[rx] = ry; // } // bool same(int x, int y) { // int rx = root(x); // int ry = root(y); // return rx == ry; // } // }; typedef struct { ll time, dead; } work; int workcmp(const void *a, const void *b) { if ((*(work *)a).dead < (*(work *)b).dead) return -1; else if ((*(work *)a).dead == (*(work *)b).dead) return 0; else return 1; } int main(void) { int N; work W[200010]; cin >> N; for (int i = 0; i < N; i++) cin >> W[i].time >> W[i].dead; qsort(W, N, sizeof(work), workcmp); ll C = 0; for (int i = 0; i < N; i++) { C += W[i].time; if (W[i].dead < C) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
replace
57
58
57
58
0
p02996
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; struct Task { long A, B; }; bool cmp(const Task &t1, const Task &t2) { if (t1.B < t2.B) { return true; } else if (t1.B > t2.B) { return false; } else { return t1.A >= t2.A; } } int main() { int N; cin >> N; vector<Task> tsk(N); long a, b; for (int i = 0; i < N; i++) { cin >> a >> b; tsk[i] = Task{a, b}; } sort(tsk.begin(), tsk.end(), cmp); long time = 0; for (int i = 0; i < N; i++) { time += tsk[i].A; if (time > tsk[i].B) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct Task { long A, B; }; bool cmp(const Task &t1, const Task &t2) { if (t1.B < t2.B) { return true; } else if (t1.B > t2.B) { return false; } else { return t1.A > t2.A; } } int main() { int N; cin >> N; vector<Task> tsk(N); long a, b; for (int i = 0; i < N; i++) { cin >> a >> b; tsk[i] = Task{a, b}; } sort(tsk.begin(), tsk.end(), cmp); long time = 0; for (int i = 0; i < N; i++) { time += tsk[i].A; if (time > tsk[i].B) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
replace
14
15
14
15
0
p02996
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<P> lis; for (int i = 0; i < N; i++) { ll a, b; cin >> a >> b; lis.push_back(P(b, a)); } sort(lis.begin(), lis.end()); ll pre = 0; for (int i = 0; i <= N; i++) { if (pre + lis.at(i).second > lis.at(i).first) { cout << "No" << endl; return 0; } pre += lis.at(i).second; } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<P> lis; for (int i = 0; i < N; i++) { ll a, b; cin >> a >> b; lis.push_back(P(b, a)); } sort(lis.begin(), lis.end()); ll pre = 0; for (int i = 0; i < N; i++) { if (pre + lis.at(i).second > lis.at(i).first) { cout << "No" << endl; return 0; } pre += lis.at(i).second; } cout << "Yes" << endl; return 0; }
replace
21
22
21
22
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02996
C++
Runtime Error
#include <bits/stdc++.h> #define Rint register int using namespace std; typedef long long LL; typedef pair<int, int> pii; const int N = 100003; template <typename T> inline void read(T &x) { int ch = getchar(); x = 0; bool flag = false; while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') { flag = true; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } if (flag) x = -x; } pii a[N]; int n; LL sum; int main() { read(n); for (Rint i = 1; i <= n; i++) read(a[i].second), read(a[i].first); sort(a + 1, a + n + 1); for (Rint i = 1; i <= n; i++) { sum += a[i].second; if (sum > a[i].first) { puts("No"); return 0; } } puts("Yes"); }
#include <bits/stdc++.h> #define Rint register int using namespace std; typedef long long LL; typedef pair<int, int> pii; const int N = 200003; template <typename T> inline void read(T &x) { int ch = getchar(); x = 0; bool flag = false; while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') { flag = true; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } if (flag) x = -x; } pii a[N]; int n; LL sum; int main() { read(n); for (Rint i = 1; i <= n; i++) read(a[i].second), read(a[i].first); sort(a + 1, a + n + 1); for (Rint i = 1; i <= n; i++) { sum += a[i].second; if (sum > a[i].first) { puts("No"); return 0; } } puts("Yes"); }
replace
5
6
5
6
0
p02996
Python
Runtime Error
import sys input = sys.stdin.readline def main(): AB = [] n = int(input()) for i in range(n): a, b = map(int, input().split()) AB.append([a, b]) AB = sorted(AB, key=lambda x: (x[1], -x[0])) time = 0 for span, dead in zip(AB): time += span if time > dead: print("No") return print("Yes") return if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): AB = [] n = int(input()) for i in range(n): a, b = map(int, input().split()) AB.append([a, b]) AB = sorted(AB, key=lambda x: (x[1], -x[0])) time = 0 for span, dead in AB: time += span if time > dead: print("No") return print("Yes") return if __name__ == "__main__": main()
replace
13
14
13
14
ValueError: not enough values to unpack (expected 2, got 1)
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02996/Python/s531558055.py", line 23, in <module> main() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02996/Python/s531558055.py", line 13, in main for span, dead in zip(AB): ValueError: not enough values to unpack (expected 2, got 1)
p02996
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int lim = 1e5 + 5; pair<int, int> jobs[lim]; bool comp(const pair<int, int> &a, const pair<int, int> &b) { return a.second < b.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> jobs[i].first >> jobs[i].second; sort(jobs, jobs + n, comp); int l = 0; for (int i = 0; i < n; i++) { if (l + jobs[i].first > jobs[i].second) { cout << "No"; return 0; } l += jobs[i].first; } cout << "Yes"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int lim = 2e5 + 5; pair<int, int> jobs[lim]; bool comp(const pair<int, int> &a, const pair<int, int> &b) { return a.second < b.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> jobs[i].first >> jobs[i].second; sort(jobs, jobs + n, comp); int l = 0; for (int i = 0; i < n; i++) { if (l + jobs[i].first > jobs[i].second) { cout << "No"; return 0; } l += jobs[i].first; } cout << "Yes"; return 0; }
replace
3
4
3
4
0
p02996
C++
Runtime Error
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include <bits/stdc++.h> using namespace std; #define y1 y11 #define fi first #define se second #define pi acos(-1.0) #define LL long long // #define mp make_pair #define pb push_back #define ls rt << 1, l, m #define rs rt << 1 | 1, m + 1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pli pair<LL, int> #define pii pair<int, int> #define piii pair<int, pii> #define puu pair<ULL, ULL> #define pdd pair<long double, long double> #define mem(a, b) memset(a, b, sizeof(a)) #define fio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define fopen \ freopen("in.txt", "r", stdin); \ freopen("out.txt", "w", stout); // head const int N = 1e5 + 5; pii a[N]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d %d", &a[i].se, &a[i].fi); int now = 0; sort(a + 1, a + 1 + n); for (int i = 1; i <= n; ++i) { if (now + a[i].se > a[i].fi) return 0 * puts("No\n"); now += a[i].se; } printf("Yes\n"); return 0; }
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include <bits/stdc++.h> using namespace std; #define y1 y11 #define fi first #define se second #define pi acos(-1.0) #define LL long long // #define mp make_pair #define pb push_back #define ls rt << 1, l, m #define rs rt << 1 | 1, m + 1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pli pair<LL, int> #define pii pair<int, int> #define piii pair<int, pii> #define puu pair<ULL, ULL> #define pdd pair<long double, long double> #define mem(a, b) memset(a, b, sizeof(a)) #define fio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define fopen \ freopen("in.txt", "r", stdin); \ freopen("out.txt", "w", stout); // head const int N = 2e5 + 5; pii a[N]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d %d", &a[i].se, &a[i].fi); int now = 0; sort(a + 1, a + 1 + n); for (int i = 1; i <= n; ++i) { if (now + a[i].se > a[i].fi) return 0 * puts("No\n"); now += a[i].se; } printf("Yes\n"); return 0; }
replace
31
32
31
32
0
p02996
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define sq(x) ((x) * (x)) #define bit(x) bitset<32>(x) #define vsort(v) sort(v.begin(), v.end()) #define rvsort(v) sort(v.begin(), v.end(), greater<llint>()) #define debug(x) cout << #x << " " << (x) << endl #define ci cin #define co cout #define en endl #define ln cout << '\n' #define pb push_back #define fi first #define se second #define MOD 1000000007 typedef long long int llint; typedef pair<int, int> pii; typedef pair<llint, llint> pll; typedef vector<int> vi; typedef vector<llint> vl; typedef vector<pii> vii; typedef vector<pll> vll; template <typename Tn> Tn __lcm(Tn a, Tn b) { return a / __gcd(a, b) * b; } int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int n; struct ab { int a, b; ab() {} ab(int a, int b) : a(a), b(b) {} bool operator<(const ab &a) const { return b < a.b; } }; int main() { ci >> n; vector<ab> v; rep(i, 0, n) { int a, b; ci >> a >> b; v.pb(ab(a, b)); } vsort(v); int t = 0; rep(i, 0, n) { if (v[i].b - (t + v[i].a) < 0) { co << "No" << en; return 0; } int remain_power = v[i].b - (t + v[i].a); rep(j, i + 1, n) { if (v[j].a >= remain_power) { v[j].a -= remain_power; break; } else { remain_power -= v[j].a; v[j].a = 0; } } t = v[i].b; } co << "Yes" << en; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define sq(x) ((x) * (x)) #define bit(x) bitset<32>(x) #define vsort(v) sort(v.begin(), v.end()) #define rvsort(v) sort(v.begin(), v.end(), greater<llint>()) #define debug(x) cout << #x << " " << (x) << endl #define ci cin #define co cout #define en endl #define ln cout << '\n' #define pb push_back #define fi first #define se second #define MOD 1000000007 typedef long long int llint; typedef pair<int, int> pii; typedef pair<llint, llint> pll; typedef vector<int> vi; typedef vector<llint> vl; typedef vector<pii> vii; typedef vector<pll> vll; template <typename Tn> Tn __lcm(Tn a, Tn b) { return a / __gcd(a, b) * b; } int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int n; struct ab { int a, b; ab() {} ab(int a, int b) : a(a), b(b) {} bool operator<(const ab &a) const { return b < a.b; } }; int main() { ci >> n; vector<ab> v; rep(i, 0, n) { int a, b; ci >> a >> b; v.pb(ab(a, b)); } vsort(v); int t = 0; rep(i, 0, n) { if (v[i].b - (t + v[i].a) < 0) { co << "No" << en; return 0; } t += v[i].a; } co << "Yes" << en; return 0; }
replace
66
79
66
67
TLE
p02996
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long n, num; pair<int, int> p[100010]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> p[i].second >> p[i].first; sort(p, p + n); for (int i = 0; i < n;) { int j = i; while (p[i].first == p[j].first) num += p[j++].second; if (num > p[i].first) { cout << "No" << endl; return 0; } i = j; } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, num; pair<int, int> p[200010]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> p[i].second >> p[i].first; sort(p, p + n); for (int i = 0; i < n;) { int j = i; while (p[i].first == p[j].first) num += p[j++].second; if (num > p[i].first) { cout << "No" << endl; return 0; } i = j; } cout << "Yes" << endl; return 0; }
replace
3
4
3
4
0
p02996
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; #define rep(i, m, n) for (int i = m; i < n; i++) #define ll long long #define MOD 1000000007 bool pair_comp_eq(pair<ll, ll> a, pair<ll, ll> b) { return a.second <= b.second; } int main(int argc, char *argv[]) { int n; vector<pair<ll, ll>> v; ll a, b; cin >> n; rep(i, 0, n) { cin >> a >> b; v.push_back(pair<ll, ll>(a, b)); } sort(v.begin(), v.end(), pair_comp_eq); ll t = 0; rep(i, 0, n) { t += v[i].first; if (t > v[i].second) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; #define rep(i, m, n) for (int i = m; i < n; i++) #define ll long long #define MOD 1000000007 bool pair_comp_eq(pair<ll, ll> a, pair<ll, ll> b) { if (a.second == b.second) { return a.first <= b.first; } else { return a.second <= b.second; } } int main(int argc, char *argv[]) { int n; vector<pair<ll, ll>> v; ll a, b; cin >> n; rep(i, 0, n) { cin >> a >> b; v.push_back(pair<ll, ll>(a, b)); } sort(v.begin(), v.end(), pair_comp_eq); ll t = 0; rep(i, 0, n) { t += v[i].first; if (t > v[i].second) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
replace
11
12
11
16
0
p02996
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; struct Pair { int A; int B; bool operator<(const Pair &X) const { return B == X.B ? A > X.A : B < X.B; } }; Pair X[100010]; int main() { int i; int N; long long iSum; ios::sync_with_stdio(false); cin.tie(0); cin >> N; for (i = 0; i < N; i++) { cin >> X[i].A; cin >> X[i].B; } sort(X, X + N); iSum = 0; for (i = 0; i < N; i++) { iSum += X[i].A; if (iSum > X[i].B) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct Pair { int A; int B; bool operator<(const Pair &X) const { return B == X.B ? A > X.A : B < X.B; } }; Pair X[200010]; int main() { int i; int N; long long iSum; ios::sync_with_stdio(false); cin.tie(0); cin >> N; for (i = 0; i < N; i++) { cin >> X[i].A; cin >> X[i].B; } sort(X, X + N); iSum = 0; for (i = 0; i < N; i++) { iSum += X[i].A; if (iSum > X[i].B) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
replace
11
12
11
12
0
p02996
C++
Runtime Error
#ifndef LOCAL #pragma GCC optimize("Ofast") #endif #include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> using namespace std; using i64 = int_fast64_t; using pii = pair<int, int>; using pli = pair<int_fast64_t, int>; using pll = pair<int_fast64_t, int_fast64_t>; template <class T> using heap = priority_queue<T>; template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <class T> constexpr T inf = numeric_limits<T>::max() / (T)2 - (T)123456; constexpr int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; constexpr int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; constexpr long double Pi = 3.1415926535897932384626433832795; constexpr long double Golden = 1.61803398874989484820; constexpr long double eps = 1e-15; #define iostream_untie true #define mod 1000000007LL #define stdout_precision 10 #define stderr_precision 10 #define itrep(i, v) for (auto i = begin(v); i != end(v); ++i) #define ritrep(i, v) for (auto i = rbegin(v); i != rend(v); ++i) #define rep(i, n) for (int_fast64_t i = 0; i < (int_fast64_t)(n); ++i) #define rrep(i, n) for (int_fast64_t i = (int_fast64_t)(n)-1; i >= 0; --i) #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define fir first #define sec second #define u_map unordered_map #define u_set unordered_set #define l_bnd lower_bound #define u_bnd upper_bound #define emp emplace #define emf emplace_front #define emb emplace_back #define pof pop_front #define pob pop_back #define mkp make_pair #define mkt make_tuple #define popcnt __builtin_popcount namespace setup { struct setupper { setupper() { if (iostream_untie) { ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); std::cerr.tie(nullptr); } std::cout << std::fixed << std::setprecision(stdout_precision); std::cerr << std::fixed << std::setprecision(stderr_precision); #ifdef LOCAL if (!freopen("stderr.txt", "wt", stderr)) { std::cerr << "Failed to open the stderr file\n"; freopen("CON", "wt", stderr); } if (!freopen("stdout.txt", "wt", stdout)) { std::cerr << "Failed to open the stdout file\n"; freopen("CON", "wt", stdout); } if (!freopen("stdin.txt", "rt", stdin)) { std::cerr << "Failed to open the stdin file.\n"; freopen("CON", "rt", stdin); } // auto print_atexit = []() { // std::cerr << "Exec time : " << clock() / (double)CLOCKS_PER_SEC * // 1000.0 << "ms\n"; std::cerr << "------------\n"; // }; // atexit((void(*)())print_atexit); #endif } } __setupper; } // namespace setup namespace std { template <class RAitr> void rsort(RAitr __first, RAitr __last) { sort(__first, __last, greater<>()); } template <class T> void hash_combine(size_t &seed, T const &key) { seed ^= hash<T>()(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } template <class T, class U> struct hash<pair<T, U>> { size_t operator()(pair<T, U> const &pr) const { size_t seed = 0; hash_combine(seed, pr.first); hash_combine(seed, pr.second); return seed; } }; template <class tuple_t, size_t index = tuple_size<tuple_t>::value - 1> struct hashval_calc { static void apply(size_t &seed, tuple_t const &t) { hashval_calc<tuple_t, index - 1>::apply(seed, t); hash_combine(seed, get<index>(t)); } }; template <class tuple_t> struct hashval_calc<tuple_t, 0> { static void apply(size_t &seed, tuple_t const &t) { hash_combine(seed, get<0>(t)); } }; template <class... T> struct hash<tuple<T...>> { size_t operator()(tuple<T...> const &t) const { size_t seed = 0; hashval_calc<tuple<T...>>::apply(seed, t); return seed; } }; } // namespace std template <class T, class U> istream &operator>>(istream &s, pair<T, U> &p) { return s >> p.first >> p.second; } template <class T, class U> ostream &operator<<(ostream &s, const pair<T, U> p) { return s << p.first << " " << p.second; } template <class T> istream &operator>>(istream &s, vector<T> &v) { for (T &e : v) { s >> e; } return s; } template <class T> ostream &operator<<(ostream &s, const vector<T> &v) { for (size_t i = 0; i < v.size(); ++i) { s << (i ? " " : "") << v[i]; } return s; } template <class tuple_t, size_t index> struct tupleos { static ostream &apply(ostream &s, const tuple_t &t) { tupleos<tuple_t, index - 1>::apply(s, t); return s << " " << get<index>(t); } }; template <class tuple_t> struct tupleos<tuple_t, 0> { static ostream &apply(ostream &s, const tuple_t &t) { return s << get<0>(t); } }; template <class... T> ostream &operator<<(ostream &s, const tuple<T...> &t) { return tupleos<tuple<T...>, tuple_size<tuple<T...>>::value - 1>::apply(s, t); } template <> ostream &operator<<(ostream &s, const tuple<> &t) { return s; } #define dump(...) \ cerr << " [ " << __LINE__ << " : " << __FUNCTION__ << " ] " << #__VA_ARGS__ \ << " : "; \ dump_func(__VA_ARGS__) template <class T> void dump_func(T x) { cerr << x << '\n'; } template <class T, class... Rest> void dump_func(T x, Rest... rest) { cerr << x << ","; dump_func(rest...); } template <class T = i64> T read() { T x; return cin >> x, x; } template <class T> void write(T x) { cout << x << '\n'; } template <class T, class... Rest> void write(T x, Rest... rest) { cout << x << ' '; write(rest...); } void writeln() {} template <class T, class... Rest> void writeln(T x, Rest... rest) { cout << x << '\n'; writeln(rest...); } #define esc(...) writeln(__VA_ARGS__), exit(0) namespace updater { template <class T> static void add(T &x, const T &y) { x += y; } template <class T> static void ext_add(T &x, const T &y, size_t w) { x += y * w; } template <class T> static void mul(T &x, const T &y) { x *= y; } template <class T> static void ext_mul(T &x, const T &y, size_t w) { x *= (T)pow(y, w); } template <class T> static bool chmax(T &x, const T &y) { return x < y ? x = y, true : false; } template <class T> static bool chmin(T &x, const T &y) { return x > y ? x = y, true : false; } }; // namespace updater using updater::add; using updater::chmax; using updater::chmin; template <class T> constexpr T minf(const T &x, const T &y) { return min(x, y); } template <class T> constexpr T maxf(const T &x, const T &y) { return max(x, y); } constexpr bool bit(i64 n, int e) { return (n >> e) & 1; } constexpr int_fast64_t mask(int_fast64_t n, int e) { return n & ((1 << e) - 1); } constexpr int ilog(int_fast64_t x, int_fast64_t b = 2) { return x ? 1 + ilog(x / b, b) : -1; } int_fast64_t binry(int_fast64_t ok, int_fast64_t ng, const function<bool(int_fast64_t)> &fn) { while (abs(ok - ng) > 1) { int_fast64_t mid = (ok + ng) / 2; (fn(mid) ? ok : ng) = mid; } return ok; } template <class A, size_t N, class T> void init(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <class T> vector<int> cmprs(const vector<T> &v) { vector<T> tmp = v; vector<int> ret; sort(begin(tmp), end(tmp)); tmp.erase(unique(begin(tmp), end(tmp)), end(tmp)); for (T i : v) ret.emplace_back(lower_bound(begin(tmp), end(tmp), i) - begin(tmp)); return ret; } template <class T> vector<int> cmprs(const T *__first, const T *__last) { return cmprs(vector<T>(__first, __last)); } void for_subset(int_fast64_t s, const function<void(int_fast64_t)> &fn) { int_fast64_t tmp = s; do { fn(tmp); } while ((--tmp &= s) != s); } /* The main code follows. */ int n; pii tas[1 << 17]; signed main() { cin >> n; rep(i, n) { cin >> tas[i].sec >> tas[i].fir; } sort(tas, tas + n); int t = 0; rep(i, n) { t += tas[i].sec; if (t > tas[i].fir) { esc("No"); } } esc("Yes"); }
#ifndef LOCAL #pragma GCC optimize("Ofast") #endif #include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> using namespace std; using i64 = int_fast64_t; using pii = pair<int, int>; using pli = pair<int_fast64_t, int>; using pll = pair<int_fast64_t, int_fast64_t>; template <class T> using heap = priority_queue<T>; template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <class T> constexpr T inf = numeric_limits<T>::max() / (T)2 - (T)123456; constexpr int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; constexpr int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; constexpr long double Pi = 3.1415926535897932384626433832795; constexpr long double Golden = 1.61803398874989484820; constexpr long double eps = 1e-15; #define iostream_untie true #define mod 1000000007LL #define stdout_precision 10 #define stderr_precision 10 #define itrep(i, v) for (auto i = begin(v); i != end(v); ++i) #define ritrep(i, v) for (auto i = rbegin(v); i != rend(v); ++i) #define rep(i, n) for (int_fast64_t i = 0; i < (int_fast64_t)(n); ++i) #define rrep(i, n) for (int_fast64_t i = (int_fast64_t)(n)-1; i >= 0; --i) #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define fir first #define sec second #define u_map unordered_map #define u_set unordered_set #define l_bnd lower_bound #define u_bnd upper_bound #define emp emplace #define emf emplace_front #define emb emplace_back #define pof pop_front #define pob pop_back #define mkp make_pair #define mkt make_tuple #define popcnt __builtin_popcount namespace setup { struct setupper { setupper() { if (iostream_untie) { ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); std::cerr.tie(nullptr); } std::cout << std::fixed << std::setprecision(stdout_precision); std::cerr << std::fixed << std::setprecision(stderr_precision); #ifdef LOCAL if (!freopen("stderr.txt", "wt", stderr)) { std::cerr << "Failed to open the stderr file\n"; freopen("CON", "wt", stderr); } if (!freopen("stdout.txt", "wt", stdout)) { std::cerr << "Failed to open the stdout file\n"; freopen("CON", "wt", stdout); } if (!freopen("stdin.txt", "rt", stdin)) { std::cerr << "Failed to open the stdin file.\n"; freopen("CON", "rt", stdin); } // auto print_atexit = []() { // std::cerr << "Exec time : " << clock() / (double)CLOCKS_PER_SEC * // 1000.0 << "ms\n"; std::cerr << "------------\n"; // }; // atexit((void(*)())print_atexit); #endif } } __setupper; } // namespace setup namespace std { template <class RAitr> void rsort(RAitr __first, RAitr __last) { sort(__first, __last, greater<>()); } template <class T> void hash_combine(size_t &seed, T const &key) { seed ^= hash<T>()(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } template <class T, class U> struct hash<pair<T, U>> { size_t operator()(pair<T, U> const &pr) const { size_t seed = 0; hash_combine(seed, pr.first); hash_combine(seed, pr.second); return seed; } }; template <class tuple_t, size_t index = tuple_size<tuple_t>::value - 1> struct hashval_calc { static void apply(size_t &seed, tuple_t const &t) { hashval_calc<tuple_t, index - 1>::apply(seed, t); hash_combine(seed, get<index>(t)); } }; template <class tuple_t> struct hashval_calc<tuple_t, 0> { static void apply(size_t &seed, tuple_t const &t) { hash_combine(seed, get<0>(t)); } }; template <class... T> struct hash<tuple<T...>> { size_t operator()(tuple<T...> const &t) const { size_t seed = 0; hashval_calc<tuple<T...>>::apply(seed, t); return seed; } }; } // namespace std template <class T, class U> istream &operator>>(istream &s, pair<T, U> &p) { return s >> p.first >> p.second; } template <class T, class U> ostream &operator<<(ostream &s, const pair<T, U> p) { return s << p.first << " " << p.second; } template <class T> istream &operator>>(istream &s, vector<T> &v) { for (T &e : v) { s >> e; } return s; } template <class T> ostream &operator<<(ostream &s, const vector<T> &v) { for (size_t i = 0; i < v.size(); ++i) { s << (i ? " " : "") << v[i]; } return s; } template <class tuple_t, size_t index> struct tupleos { static ostream &apply(ostream &s, const tuple_t &t) { tupleos<tuple_t, index - 1>::apply(s, t); return s << " " << get<index>(t); } }; template <class tuple_t> struct tupleos<tuple_t, 0> { static ostream &apply(ostream &s, const tuple_t &t) { return s << get<0>(t); } }; template <class... T> ostream &operator<<(ostream &s, const tuple<T...> &t) { return tupleos<tuple<T...>, tuple_size<tuple<T...>>::value - 1>::apply(s, t); } template <> ostream &operator<<(ostream &s, const tuple<> &t) { return s; } #define dump(...) \ cerr << " [ " << __LINE__ << " : " << __FUNCTION__ << " ] " << #__VA_ARGS__ \ << " : "; \ dump_func(__VA_ARGS__) template <class T> void dump_func(T x) { cerr << x << '\n'; } template <class T, class... Rest> void dump_func(T x, Rest... rest) { cerr << x << ","; dump_func(rest...); } template <class T = i64> T read() { T x; return cin >> x, x; } template <class T> void write(T x) { cout << x << '\n'; } template <class T, class... Rest> void write(T x, Rest... rest) { cout << x << ' '; write(rest...); } void writeln() {} template <class T, class... Rest> void writeln(T x, Rest... rest) { cout << x << '\n'; writeln(rest...); } #define esc(...) writeln(__VA_ARGS__), exit(0) namespace updater { template <class T> static void add(T &x, const T &y) { x += y; } template <class T> static void ext_add(T &x, const T &y, size_t w) { x += y * w; } template <class T> static void mul(T &x, const T &y) { x *= y; } template <class T> static void ext_mul(T &x, const T &y, size_t w) { x *= (T)pow(y, w); } template <class T> static bool chmax(T &x, const T &y) { return x < y ? x = y, true : false; } template <class T> static bool chmin(T &x, const T &y) { return x > y ? x = y, true : false; } }; // namespace updater using updater::add; using updater::chmax; using updater::chmin; template <class T> constexpr T minf(const T &x, const T &y) { return min(x, y); } template <class T> constexpr T maxf(const T &x, const T &y) { return max(x, y); } constexpr bool bit(i64 n, int e) { return (n >> e) & 1; } constexpr int_fast64_t mask(int_fast64_t n, int e) { return n & ((1 << e) - 1); } constexpr int ilog(int_fast64_t x, int_fast64_t b = 2) { return x ? 1 + ilog(x / b, b) : -1; } int_fast64_t binry(int_fast64_t ok, int_fast64_t ng, const function<bool(int_fast64_t)> &fn) { while (abs(ok - ng) > 1) { int_fast64_t mid = (ok + ng) / 2; (fn(mid) ? ok : ng) = mid; } return ok; } template <class A, size_t N, class T> void init(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <class T> vector<int> cmprs(const vector<T> &v) { vector<T> tmp = v; vector<int> ret; sort(begin(tmp), end(tmp)); tmp.erase(unique(begin(tmp), end(tmp)), end(tmp)); for (T i : v) ret.emplace_back(lower_bound(begin(tmp), end(tmp), i) - begin(tmp)); return ret; } template <class T> vector<int> cmprs(const T *__first, const T *__last) { return cmprs(vector<T>(__first, __last)); } void for_subset(int_fast64_t s, const function<void(int_fast64_t)> &fn) { int_fast64_t tmp = s; do { fn(tmp); } while ((--tmp &= s) != s); } /* The main code follows. */ int n; pii tas[1 << 18]; signed main() { cin >> n; rep(i, n) { cin >> tas[i].sec >> tas[i].fir; } sort(tas, tas + n); int t = 0; rep(i, n) { t += tas[i].sec; if (t > tas[i].fir) { esc("No"); } } esc("Yes"); }
replace
253
254
253
254
0
p02996
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; pair<int, int> X[100100]; int main() { int N; cin >> N; for (int i = 0; i < N; i++) cin >> X[i].second >> X[i].first; sort(X, X + N); int Time = 0; for (int i = 0; i < N; i++) { Time += X[i].second; if (Time > X[i].first) { puts("No"); return 0; } } puts("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; pair<int, int> X[200200]; int main() { int N; cin >> N; for (int i = 0; i < N; i++) cin >> X[i].second >> X[i].first; sort(X, X + N); int Time = 0; for (int i = 0; i < N; i++) { Time += X[i].second; if (Time > X[i].first) { puts("No"); return 0; } } puts("Yes"); return 0; }
replace
2
3
2
3
0
p02996
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; bool compare(pair<long long, long long> a, pair<long long, long long> b) { return a.second < b.second; } int N; vector<pair<long long, long long>> v; int main() { cin >> N; for (int i = 0; i < N; ++i) cin >> v[i].first >> v[i].second; sort(v.begin(), v.end(), compare); bool ok = true; long long sum = 0; for (int i = 0; i < N; ++i) { sum += v[i].first; if (sum > v[i].second) ok = false; } if (ok) cout << "Yes" << endl; else cout << "No" << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; bool compare(pair<long long, long long> a, pair<long long, long long> b) { return a.second < b.second; } int N; vector<pair<long long, long long>> v; int main() { cin >> N; v.resize(N); for (int i = 0; i < N; ++i) cin >> v[i].first >> v[i].second; sort(v.begin(), v.end(), compare); bool ok = true; long long sum = 0; for (int i = 0; i < N; ++i) { sum += v[i].first; if (sum > v[i].second) ok = false; } if (ok) cout << "Yes" << endl; else cout << "No" << endl; }
insert
15
15
15
17
-11
p02997
C++
Time Limit Exceeded
#include <bits/stdc++.h> const long long INF = 1LL << 60; const long long MOD = 1000000007; const double PI = acos(-1.0); #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define perm(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define drop(x) cout << (x) << '\n', exit(0) #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair<ll, ll> P; typedef vector<ll> vec; typedef vector<vector<ll>> vec2; typedef vector<vector<vector<ll>>> vec3; template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class S, class T> inline bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline ll msb(ll v) { return 1 << (31 - __builtin_clzll(v)); } inline ll devc(ll x, ll y) { return (x + y - 1) / y; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; 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 T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) { os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; } template <typename T1, typename T2, typename T3> istream &operator>>(istream &is, tuple<T1, T2, T3> &t) { is >> get<0>(t) >> get<1>(t) >> get<2>(t); 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; } /*--------------------------------- Tools * ------------------------------------------*/ template <typename T> vector<T> cumsum(const vector<T> &X) { vector<T> res(X.size() + 1, 0); for (int i = 0; i < X.size(); ++i) res[i + 1] += res[i] + X[i]; return res; } template <typename S, typename T, typename F> pair<T, T> bisearch(S left, T right, F f) { while (abs(right - left) > 1) { T mid = (right + left) / 2; if (f(mid)) right = mid; else left = mid; } return {left, right}; } template <typename S, typename T, typename F> double trisearch(S left, T right, F f, int maxLoop = 90) { double low = left, high = right; while (maxLoop--) { double mid_left = high / 3 + low * 2 / 3; double mid_right = high * 2 / 3 + low / 3; if (f(mid_left) >= f(mid_right)) low = mid_left; else high = mid_right; } return (low + high) * 0.5; } /*------------------------------- Main Code Here * -----------------------------------------*/ int main() { ll N, K; cin >> N >> K; if (K > (N - 1) * (N - 2) / 2) drop(-1); vector<P> ans; rep1(i, N - 1) ans.pb({i, N}); ll dif = (N - 1) * (N - 2) / 2 - K; ll now = 0; bool flag = true; while (flag) { ++now; for (ll i = now + 1; i <= N - 1; ++i) { ans.pb({now, i}); --dif; if (!dif) { flag = false; break; } } } print(len(ans)); for (auto a : ans) print(a); return 0; }
#include <bits/stdc++.h> const long long INF = 1LL << 60; const long long MOD = 1000000007; const double PI = acos(-1.0); #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define perm(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define drop(x) cout << (x) << '\n', exit(0) #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair<ll, ll> P; typedef vector<ll> vec; typedef vector<vector<ll>> vec2; typedef vector<vector<vector<ll>>> vec3; template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class S, class T> inline bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline ll msb(ll v) { return 1 << (31 - __builtin_clzll(v)); } inline ll devc(ll x, ll y) { return (x + y - 1) / y; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; 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 T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) { os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; } template <typename T1, typename T2, typename T3> istream &operator>>(istream &is, tuple<T1, T2, T3> &t) { is >> get<0>(t) >> get<1>(t) >> get<2>(t); 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; } /*--------------------------------- Tools * ------------------------------------------*/ template <typename T> vector<T> cumsum(const vector<T> &X) { vector<T> res(X.size() + 1, 0); for (int i = 0; i < X.size(); ++i) res[i + 1] += res[i] + X[i]; return res; } template <typename S, typename T, typename F> pair<T, T> bisearch(S left, T right, F f) { while (abs(right - left) > 1) { T mid = (right + left) / 2; if (f(mid)) right = mid; else left = mid; } return {left, right}; } template <typename S, typename T, typename F> double trisearch(S left, T right, F f, int maxLoop = 90) { double low = left, high = right; while (maxLoop--) { double mid_left = high / 3 + low * 2 / 3; double mid_right = high * 2 / 3 + low / 3; if (f(mid_left) >= f(mid_right)) low = mid_left; else high = mid_right; } return (low + high) * 0.5; } /*------------------------------- Main Code Here * -----------------------------------------*/ int main() { ll N, K; cin >> N >> K; if (K > (N - 1) * (N - 2) / 2) drop(-1); vector<P> ans; rep1(i, N - 1) ans.pb({i, N}); ll dif = (N - 1) * (N - 2) / 2 - K; ll now = 0; bool flag = true; while (flag) { if (dif == 0) break; ++now; for (ll i = now + 1; i <= N - 1; ++i) { ans.pb({now, i}); --dif; if (!dif) { flag = false; break; } } } print(len(ans)); for (auto a : ans) print(a); return 0; }
insert
143
143
143
145
TLE
p02997
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int using namespace std; const ll mod = 1000000007; const ll inf = 1e18; int main() { ll n, k; cin >> n >> k; ll m = 0; vector<vector<ll>> v; if (k > (n - 2) * (n - 1) / 2) cout << -1 << endl; else { queue<vector<ll>> G; for (int i = 2; i < n; i++) { for (int j = i + 1; j < n; j++) G.push({i, j}); } for (int i = 2; i <= n; i++) { v.push_back({1, i}); m++; } for (int i = 0; i < (n - 1) * (n - 2) / 2 - k; i++) { vector<ll> u = G.front(); G.pop(); v.push_back(u); m++; } cout << m << endl; for (int i = 0; i < m; i++) cout << v[i][0] << " " << v[i][1] << endl; } }
#include <bits/stdc++.h> #define ll long long int using namespace std; const ll mod = 1000000007; const ll inf = 1e18; int main() { ll n, k; cin >> n >> k; ll m = 0; vector<vector<ll>> v; if (k > (n - 2) * (n - 1) / 2) cout << -1 << endl; else { queue<vector<ll>> G; for (int i = 2; i < n; i++) { for (int j = i + 1; j <= n; j++) G.push({i, j}); } for (int i = 2; i <= n; i++) { v.push_back({1, i}); m++; } for (int i = 0; i < (n - 1) * (n - 2) / 2 - k; i++) { vector<ll> u = G.front(); G.pop(); v.push_back(u); m++; } cout << m << endl; for (int i = 0; i < m; i++) cout << v[i][0] << " " << v[i][1] << endl; } }
replace
21
22
21
22
0
p02997
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; const int MAXN = 105; int n, k, ans, t, la = 2; int ansn, Ans1[MAXN], Ans2[MAXN]; void Print() { printf("%d\n", ansn); for (int i = 1; i <= ansn; i++) printf("%d %d\n", Ans1[i], Ans2[i]); } int main() { scanf("%d%d", &n, &k); if ((n - 1) * (n - 2) / 2 < k) { printf("-1\n"); return 0; } for (int i = 2; i <= n; i++) { ansn++; Ans1[ansn] = 1; Ans2[ansn] = i; } t = (n - 1) * (n - 2) / 2 - k; for (int i = 2; i <= n; i++) for (int j = i + 1; j <= n; j++) { if (t == 0) { Print(); return 0; } t--; ansn++; Ans1[ansn] = i; Ans2[ansn] = j; } Print(); }
#include <algorithm> #include <cstdio> using namespace std; const int MAXN = 10005; int n, k, ans, t, la = 2; int ansn, Ans1[MAXN], Ans2[MAXN]; void Print() { printf("%d\n", ansn); for (int i = 1; i <= ansn; i++) printf("%d %d\n", Ans1[i], Ans2[i]); } int main() { scanf("%d%d", &n, &k); if ((n - 1) * (n - 2) / 2 < k) { printf("-1\n"); return 0; } for (int i = 2; i <= n; i++) { ansn++; Ans1[ansn] = 1; Ans2[ansn] = i; } t = (n - 1) * (n - 2) / 2 - k; for (int i = 2; i <= n; i++) for (int j = i + 1; j <= n; j++) { if (t == 0) { Print(); return 0; } t--; ansn++; Ans1[ansn] = i; Ans2[ansn] = j; } Print(); }
replace
3
4
3
4
0
p02997
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, m) for (long long i = 0; i < m; i++) #define per(i, m) for (long long i = m - 1; i >= 0; i--) #define FOR(i, n, m) for (long long i = n; i < m; i++) #define ROF(i, n, m) for (long long i = m - 1; i >= n; i--) #define SORT(v, n) \ do { \ sort(v, v + n); \ reverse(v, v + n); \ } while (0) #define all(x) (x).begin(), (x).end() #define EPS (1e-7) #define INF (1e18) #define PI (acos(-1)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using namespace std; typedef long long ll; const ll MOD = 1000000007; typedef pair<ll, ll> LP; ll POW(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW(x * x, n / 2) % MOD; return x % MOD * POW(x, n - 1) % MOD; } ll POW2(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW2(x * x, n / 2); return x * POW2(x, n - 1); } ll POW3(ll x, ll n, ll m) { x %= m; if (n == 0) return 1; if (n % 2 == 0) return POW3(x * x, n / 2, m) % m; return x * POW3(x, n - 1, m) % m; } ll gcd(ll u, ll v) { ll r; while (0 != v) { r = u % v; u = v; v = r; } return u; } ll lcm(ll u, ll v) { return u * v / gcd(u, v); } ll KAI(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI(m - 1) % MOD; } ll KAI2(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI2(m - 1); } ll extGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } inline ll mod(ll a, ll m) { return (a % m + m) % m; } ll modinv(ll a) { ll x, y; extGCD(a, MOD, x, y); return mod(x, MOD); } ll COM(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI(m) % MOD * modinv(KAI(n) % MOD * KAI(m - n) % MOD) % MOD; } ll COM2(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI2(m) / KAI2(n) / KAI2(m - n); } ll DEC(ll x, ll m, ll n) // xのm進数でのx^nの位の値 { return x % POW(m, n + 1) / POW(m, n); } ll keta(ll x, ll n) // xのn進数での桁数 { if (x == 0) return 0; return keta(x / n, n) + 1; } ll DIV(ll x, ll n) // x!のnで割り切れる回数 { if (x == 0) return 0; return x / n + DIV(x / n, n); } ll ORD(ll x, ll n) // xのnで割り切れる回数 { if (x == 0) return INF; if (x % n != 0) return 0; return 1 + ORD(x / n, n); } ll SGS(ll x, ll y, ll m) // 1+x+…+x^(y-1)をmで割った余り { if (y == 0) return 0; if (y % 2 == 0) { return (1 + POW3(x, y / 2, m)) * SGS(x, y / 2, m) % m; } return (1 + x * SGS(x, y - 1, m)) % m; } ll SSGS(ll x, ll y, ll m) // Σ[k=1→y](1+x+…+x^(k-1))をmで割った余り { if (y == 0) return 0; if (y == 1) return 1; if (y % 2 == 0) { return (SSGS(x, y / 2, m) * (POW3(x, y / 2, m) + 1) % m + SGS(x, y / 2, m) * y / 2 % m) % m; } return (SSGS(x, y - 1, m) * x % m + y) % m; } ll c = 0; void mon(ll n, ll k) { if (k <= (n - 2) * (n - 3) / 2) { // FOR(i,1,n)printf("%lld %lld\n",i,n); c += n - 1; mon(n - 1, k); return; } else { FOR(i, 2, n + 1) { // printf("%lld 1\n",i); c++; } rep(i, ((n - 1) * (n - 2) / 2 - k) / 3) { // printf("%lld %lld\n",2+3*i,3+3*i); // printf("%lld %lld\n",4+3*i,2+3*i); // printf("%lld %lld\n",4+3*i,3+3*i); c += 3; } if (((n - 1) * (n - 2) / 2 - k) % 3 == 1) { // printf("%lld %lld\n",2+((n-1)*(n-2)/2-k)/3*3,3+((n-1)*(n-2)/2-k)/3*3); c++; } if (((n - 1) * (n - 2) / 2 - k) % 3 == 2) { // printf("%lld %lld\n",2+((n-1)*(n-2)/2-k)/3*3,3+((n-1)*(n-2)/2-k)/3*3); // printf("%lld %lld\n",4+((n-1)*(n-2)/2-k)/3*3,5+((n-1)*(n-2)/2-k)/3*3); c += 2; } return; } } void mon2(ll n, ll k) { if (k <= (n - 2) * (n - 3) / 2) { FOR(i, 1, n) printf("%lld %lld\n", i, n); mon2(n - 1, k); return; } else { FOR(i, 2, n + 1) printf("%lld 1\n", i); rep(i, ((n - 1) * (n - 2) / 2 - k) / 3) { printf("%lld %lld\n", 2 + 3 * i, 3 + 3 * i); printf("%lld %lld\n", 4 + 3 * i, 2 + 3 * i); printf("%lld %lld\n", 4 + 3 * i, 3 + 3 * i); } if (((n - 1) * (n - 2) / 2 - k) % 3 == 1) printf("%lld %lld\n", 2 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3, 3 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3); if (((n - 1) * (n - 2) / 2 - k) % 3 == 2) { printf("%lld %lld\n", 2 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3, 3 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3); printf("%lld %lld\n", 4 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3, 5 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3); } return; } } int main() { ll n, k; cin >> n >> k; if (k > (n - 1) * (n - 2) / 2) printf("-1"); else { mon(n, k); printf("%lld\n", c); mon2(n, k); } }
#include <bits/stdc++.h> #define rep(i, m) for (long long i = 0; i < m; i++) #define per(i, m) for (long long i = m - 1; i >= 0; i--) #define FOR(i, n, m) for (long long i = n; i < m; i++) #define ROF(i, n, m) for (long long i = m - 1; i >= n; i--) #define SORT(v, n) \ do { \ sort(v, v + n); \ reverse(v, v + n); \ } while (0) #define all(x) (x).begin(), (x).end() #define EPS (1e-7) #define INF (1e18) #define PI (acos(-1)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using namespace std; typedef long long ll; const ll MOD = 1000000007; typedef pair<ll, ll> LP; ll POW(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW(x * x, n / 2) % MOD; return x % MOD * POW(x, n - 1) % MOD; } ll POW2(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW2(x * x, n / 2); return x * POW2(x, n - 1); } ll POW3(ll x, ll n, ll m) { x %= m; if (n == 0) return 1; if (n % 2 == 0) return POW3(x * x, n / 2, m) % m; return x * POW3(x, n - 1, m) % m; } ll gcd(ll u, ll v) { ll r; while (0 != v) { r = u % v; u = v; v = r; } return u; } ll lcm(ll u, ll v) { return u * v / gcd(u, v); } ll KAI(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI(m - 1) % MOD; } ll KAI2(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI2(m - 1); } ll extGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } inline ll mod(ll a, ll m) { return (a % m + m) % m; } ll modinv(ll a) { ll x, y; extGCD(a, MOD, x, y); return mod(x, MOD); } ll COM(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI(m) % MOD * modinv(KAI(n) % MOD * KAI(m - n) % MOD) % MOD; } ll COM2(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI2(m) / KAI2(n) / KAI2(m - n); } ll DEC(ll x, ll m, ll n) // xのm進数でのx^nの位の値 { return x % POW(m, n + 1) / POW(m, n); } ll keta(ll x, ll n) // xのn進数での桁数 { if (x == 0) return 0; return keta(x / n, n) + 1; } ll DIV(ll x, ll n) // x!のnで割り切れる回数 { if (x == 0) return 0; return x / n + DIV(x / n, n); } ll ORD(ll x, ll n) // xのnで割り切れる回数 { if (x == 0) return INF; if (x % n != 0) return 0; return 1 + ORD(x / n, n); } ll SGS(ll x, ll y, ll m) // 1+x+…+x^(y-1)をmで割った余り { if (y == 0) return 0; if (y % 2 == 0) { return (1 + POW3(x, y / 2, m)) * SGS(x, y / 2, m) % m; } return (1 + x * SGS(x, y - 1, m)) % m; } ll SSGS(ll x, ll y, ll m) // Σ[k=1→y](1+x+…+x^(k-1))をmで割った余り { if (y == 0) return 0; if (y == 1) return 1; if (y % 2 == 0) { return (SSGS(x, y / 2, m) * (POW3(x, y / 2, m) + 1) % m + SGS(x, y / 2, m) * y / 2 % m) % m; } return (SSGS(x, y - 1, m) * x % m + y) % m; } ll c = 0; void mon(ll n, ll k) { if (k <= (n - 2) * (n - 3) / 2) { // FOR(i,1,n)printf("%lld %lld\n",i,n); c += n - 1; mon(n - 1, k); return; } else { FOR(i, 2, n + 1) { // printf("%lld 1\n",i); c++; } rep(i, ((n - 1) * (n - 2) / 2 - k) / 3) { // printf("%lld %lld\n",2+3*i,3+3*i); // printf("%lld %lld\n",4+3*i,2+3*i); // printf("%lld %lld\n",4+3*i,3+3*i); c += 3; } if (((n - 1) * (n - 2) / 2 - k) % 3 == 1) { // printf("%lld %lld\n",2+((n-1)*(n-2)/2-k)/3*3,3+((n-1)*(n-2)/2-k)/3*3); c++; } if (((n - 1) * (n - 2) / 2 - k) % 3 == 2) { // printf("%lld %lld\n",2+((n-1)*(n-2)/2-k)/3*3,3+((n-1)*(n-2)/2-k)/3*3); // printf("%lld %lld\n",4+((n-1)*(n-2)/2-k)/3*3,5+((n-1)*(n-2)/2-k)/3*3); c += 2; } return; } } void mon2(ll n, ll k) { if (k <= (n - 2) * (n - 3) / 2) { FOR(i, 1, n) printf("%lld %lld\n", i, n); mon2(n - 1, k); return; } else { FOR(i, 2, n + 1) printf("%lld 1\n", i); rep(i, ((n - 1) * (n - 2) / 2 - k) / 3) { printf("%lld %lld\n", 2 + 3 * i, 3 + 3 * i); printf("%lld %lld\n", 4 + 3 * i, 2 + 3 * i); printf("%lld %lld\n", 4 + 3 * i, 3 + 3 * i); } if (((n - 1) * (n - 2) / 2 - k) % 3 == 1) printf("%lld %lld\n", 2 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3, 3 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3); if (((n - 1) * (n - 2) / 2 - k) % 3 == 2) { printf("%lld %lld\n", 2 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3, 3 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3); printf("%lld %lld\n", 4 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3, 5 + ((n - 1) * (n - 2) / 2 - k) / 3 * 3); } return; } } int main() { ll n, k; cin >> n >> k; if (k > (n - 1) * (n - 2) / 2) printf("-1"); else if (k == 0) { printf("%lld\n", (n - 1) * n / 2); FOR(i, 1, n) { FOR(j, i + 1, n + 1) { printf("%lld %lld\n", i, j); } } } else { mon(n, k); printf("%lld\n", c); mon2(n, k); } }
replace
232
233
232
238
TLE
p02997
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long ll int b[200005]; ll int a[200005]; bool compare(const pair<ll int, int> p1, const pair<ll int, int> p2) { if (b[p1.second] == b[p2.second]) { return p1.first < p2.first; } return b[p1.second] < b[p2.second]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { int n, k; cin >> n >> k; if (k > ((n - 1) * (n - 2)) / 2) { cout << -1 << endl; } else { cout << (n * n - n) / 2 - k << endl; int req = (n * n - n) / 2 - k; for (int i = 1; i <= n - 1; i++) { cout << n << " " << i << endl; } req -= n - 1; bool b = true; int r = 1; while (b) { for (int i = 1; i <= n - 1 - r; i++) { if (req == 0) { b = false; } else { cout << i << " " << i + r << endl; req -= 1; } } r++; } } } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long ll int b[200005]; ll int a[200005]; bool compare(const pair<ll int, int> p1, const pair<ll int, int> p2) { if (b[p1.second] == b[p2.second]) { return p1.first < p2.first; } return b[p1.second] < b[p2.second]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { int n, k; cin >> n >> k; if (k > ((n - 1) * (n - 2)) / 2) { cout << -1 << endl; } else { cout << (n * n - n) / 2 - k << endl; int req = (n * n - n) / 2 - k; for (int i = 1; i <= n - 1; i++) { cout << n << " " << i << endl; } req -= n - 1; bool b = true; int r = 1; while (b && r <= n - 2) { for (int i = 1; i <= n - 1 - r; i++) { if (req == 0) { b = false; } else { cout << i << " " << i + r << endl; req -= 1; } } r++; } } } }
replace
33
34
33
34
TLE
p02997
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, a) for (int(i) = 0; (i) < (a); ++(i)) #define Rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) #define ALLIN(v) rep(i, v.size()) cin >> v[i] #define all(v) (v).begin(), (v).end() #define bet(a, x, b) a <= x &&x < b #define fi first #define se second using namespace std; using ll = long long; using ull = unsigned long long; using arr = vector<int>; using mat = vector<arr>; using pi = pair<int, int>; template <typename T> using vec = vector<T>; template <typename T> using pq = priority_queue<T>; template <typename T> using rpq = priority_queue<T, vec<T>, greater<T>>; int main(void) { int N, K; cin >> N >> K; int able = (N - 1) * (N - 2) / 2; if (able < K) { cout << -1; return 0; } int M = N - 1 + able - K; cout << M << endl; int rem = M - N + 1, now = 2; for (int i = 2; i <= N; ++i) { cout << 1 << " " << i << endl; } while (rem > 0) { if (rem >= N - now) { for (int i = now + 1; i <= N; ++i) { cout << now << " " << i << endl; } rem -= N - now; } else { for (int i = now + 1; i <= i + rem; ++i) { cout << now << " " << i << endl; } rem = 0; } ++now; } }
#include <bits/stdc++.h> #define rep(i, a) for (int(i) = 0; (i) < (a); ++(i)) #define Rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) #define ALLIN(v) rep(i, v.size()) cin >> v[i] #define all(v) (v).begin(), (v).end() #define bet(a, x, b) a <= x &&x < b #define fi first #define se second using namespace std; using ll = long long; using ull = unsigned long long; using arr = vector<int>; using mat = vector<arr>; using pi = pair<int, int>; template <typename T> using vec = vector<T>; template <typename T> using pq = priority_queue<T>; template <typename T> using rpq = priority_queue<T, vec<T>, greater<T>>; int main(void) { int N, K; cin >> N >> K; int able = (N - 1) * (N - 2) / 2; if (able < K) { cout << -1; return 0; } int M = N - 1 + able - K; cout << M << endl; int rem = M - N + 1, now = 2; for (int i = 2; i <= N; ++i) { cout << 1 << " " << i << endl; } while (rem > 0) { if (rem >= N - now) { for (int i = now + 1; i <= N; ++i) { cout << now << " " << i << endl; } rem -= N - now; } else { for (int i = now + 1; i <= now + rem; ++i) { cout << now << " " << i << endl; } rem = 0; } ++now; } }
replace
42
43
42
43
TLE
p02997
C++
Time Limit Exceeded
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // 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()) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; // debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; // template //-------------------------------------------- template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : "\t"); } return os; } template <typename T> ostream &operator<<(ostream &s, const vector<vector<T>> &vv) { for (int i = 0; i < vv.size(); ++i) { s << vv[i] << endl; } return s; } // main code int main(int argc, char const *argv[]) { int n, k; cin >> n >> k; int n_max = (n - 1) * (n - 2) / 2; if (n_max < k) { cout << -1 << endl; return 0; } int m = n - 1 + (n_max - k); cout << m << endl; for (int i = 1; i <= n - 1; i++) { cout << 1 << " " << i + 1 << endl; } int count = 0; for (int i = 2;; i++) { for (int j = i + 1; j < n + 1; j++) { cout << i << " " << j << endl; count++; if (count == n_max - k) { return 0; } } } return 0; }
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // 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()) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; // debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; // template //-------------------------------------------- template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : "\t"); } return os; } template <typename T> ostream &operator<<(ostream &s, const vector<vector<T>> &vv) { for (int i = 0; i < vv.size(); ++i) { s << vv[i] << endl; } return s; } // main code int main(int argc, char const *argv[]) { int n, k; cin >> n >> k; int n_max = (n - 1) * (n - 2) / 2; if (n_max < k) { cout << -1 << endl; return 0; } int m = n - 1 + (n_max - k); cout << m << endl; for (int i = 1; i <= n - 1; i++) { cout << 1 << " " << i + 1 << endl; } if (n_max - k == 0) { return 0; } int count = 0; for (int i = 2;; i++) { for (int j = i + 1; j < n + 1; j++) { cout << i << " " << j << endl; count++; if (count == n_max - k) { return 0; } } } return 0; }
insert
91
91
91
94
TLE
p02997
C++
Runtime Error
#include <algorithm> #include <climits> #include <complex> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> // using using namespace std; // typedef typedef long long ll; // define #define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c)) #define REP(i, n) FOR(i, 0, n, 1) #define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c)) #define RREP(i, n) RFOR(i, n, 0, 1) #define ALL(c) (c).begin(), (c).end() #define SORT(c) sort(ALL(c)) #define REVERSE(c) reverse(ALL(c)) #define UNIQ(c) unique(ALL(c)) #define LB(c, x) lower_bound(c.begin(), c.end(), x) #define UB(c, x) upper_bound(c.begin(), c.end(), x) #define LI(c, x) distance(c.begin(), LB(c, x)) #define UI(c, x) distance(c.begin(), UB(c, x)) // functions template <class T> T ceil(T a, T b) { return (a + b - 1) / b; } template <class T> T round(T a, T b) { return (a + b / 2) / b; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } ll modpow(ll a, ll b, ll m) { if (b == 0) { return 1; } else if (b % 2 == 0) { ll h = modpow(a, b / 2, m); return h * h % m; } else { return a * modpow(a, b - 1, m) % m; } } ll comb(ll a, ll b, ll m) { if (b > a - b) { return comb(a, a - b, m); } ll c = 1, d = 1; REP(i, b) { c *= (a - i); d *= (b - i); c %= m; d %= m; } return c * modpow(d, m - 2, m) % m; } // main int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; int cnt = (N - 1) * (N - 2) / 2; if (cnt < K) { cout << -1 << endl; return 0; } int res = 0; vector<vector<bool>> G(N, vector<bool>(N, false)); FOR(i, 1, N, 1) { G[0][i] = true; res++; } int s = 1, t = 2; REP(i, cnt - K) { G[s][t] = true; res++; if (t < N - 1) { t++; } else { s++; t = s + 1; } } cout << res << endl; REP(i, N) { REP(j, N) { if (G[i + 1][j + 1]) { cout << i << " " << j << endl; } } } return 0; }
#include <algorithm> #include <climits> #include <complex> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> // using using namespace std; // typedef typedef long long ll; // define #define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c)) #define REP(i, n) FOR(i, 0, n, 1) #define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c)) #define RREP(i, n) RFOR(i, n, 0, 1) #define ALL(c) (c).begin(), (c).end() #define SORT(c) sort(ALL(c)) #define REVERSE(c) reverse(ALL(c)) #define UNIQ(c) unique(ALL(c)) #define LB(c, x) lower_bound(c.begin(), c.end(), x) #define UB(c, x) upper_bound(c.begin(), c.end(), x) #define LI(c, x) distance(c.begin(), LB(c, x)) #define UI(c, x) distance(c.begin(), UB(c, x)) // functions template <class T> T ceil(T a, T b) { return (a + b - 1) / b; } template <class T> T round(T a, T b) { return (a + b / 2) / b; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } ll modpow(ll a, ll b, ll m) { if (b == 0) { return 1; } else if (b % 2 == 0) { ll h = modpow(a, b / 2, m); return h * h % m; } else { return a * modpow(a, b - 1, m) % m; } } ll comb(ll a, ll b, ll m) { if (b > a - b) { return comb(a, a - b, m); } ll c = 1, d = 1; REP(i, b) { c *= (a - i); d *= (b - i); c %= m; d %= m; } return c * modpow(d, m - 2, m) % m; } // main int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; int cnt = (N - 1) * (N - 2) / 2; if (cnt < K) { cout << -1 << endl; return 0; } int res = 0; vector<vector<bool>> G(N, vector<bool>(N, false)); FOR(i, 1, N, 1) { G[0][i] = true; res++; } int s = 1, t = 2; REP(i, cnt - K) { G[s][t] = true; res++; if (t < N - 1) { t++; } else { s++; t = s + 1; } } cout << res << endl; REP(i, N) { REP(j, N) { if (G[i][j]) { cout << i + 1 << " " << j + 1 << endl; } } } return 0; }
replace
104
106
104
106
-11
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // types typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef vector<ll> vll; // macros #define ALL(a) a.begin(), a.end() #define SZ(a) ((int)a.size()) #define FI first #define SE second #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 FOR(i, a, b) for (int i = (a); i < (b); i++) #define PB push_back #define EB emplace_back #define MP(a, b) make_pair(a, b) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL // constants const int inf = 1e9; const ll linf = 1LL << 50; const double eps = 1e-10; const int MOD = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; vector<pll> v; REP1(i, n) v.push_back(pll(0, i)); REP1(i, n) { for (ll j = i + 1; j < n; j++) { v.push_back(pll(i, j)); } } if (k > n * (n - 1) / 2 - (n - 1)) { cout << -1 << endl; return 1; } ll m = v.size() - k; cout << m << endl; REP(i, m) cout << v[i].FI + 1 << " " << v[i].SE + 1 << endl; }
#include <bits/stdc++.h> using namespace std; // types typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef vector<ll> vll; // macros #define ALL(a) a.begin(), a.end() #define SZ(a) ((int)a.size()) #define FI first #define SE second #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 FOR(i, a, b) for (int i = (a); i < (b); i++) #define PB push_back #define EB emplace_back #define MP(a, b) make_pair(a, b) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL // constants const int inf = 1e9; const ll linf = 1LL << 50; const double eps = 1e-10; const int MOD = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; vector<pll> v; REP1(i, n) v.push_back(pll(0, i)); REP1(i, n) { for (ll j = i + 1; j < n; j++) { v.push_back(pll(i, j)); } } if (k > n * (n - 1) / 2 - (n - 1)) { cout << -1 << endl; return 0; } ll m = v.size() - k; cout << m << endl; REP(i, m) cout << v[i].FI + 1 << " " << v[i].SE + 1 << endl; }
replace
57
58
57
58
0
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; // int mod = 998244353; int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int T; // cin >> T; T = 1; while (T--) { solve(); } } void solve() { int n, k; cin >> n >> k; vector<pii> v, v2; rep(i, n) rep(j, i) { if (j == 0) v2.eb(j + 1, i + 1); else v.eb(j + 1, i + 1); } if (k > n) { cout << -1 << endl; return; } rep(i, k) { v.pop_back(); } v.insert(v.end(), all(v2)); cout << sz(v) << endl; rep(i, sz(v)) cout << v[i] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; // int mod = 998244353; int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int T; // cin >> T; T = 1; while (T--) { solve(); } } void solve() { int n, k; cin >> n >> k; vector<pii> v, v2; rep(i, n) rep(j, i) { if (j == 0) v2.eb(j + 1, i + 1); else v.eb(j + 1, i + 1); } if (k > n * (n - 1) / 2 - (n - 1)) { cout << -1 << endl; return; } rep(i, k) { v.pop_back(); } v.insert(v.end(), all(v2)); cout << sz(v) << endl; rep(i, sz(v)) cout << v[i] << endl; }
replace
92
93
92
93
0
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define dump(...) #endif #define endl "\n" #define ll long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define INF 2147483647 #define LLINF 9223372036854775807LL #define vi vector<int> #define vvi vector<vector<int>> #define pi pair<int, int> #define ALL(a) (a).begin(), (a).end() #define BIT(n) (1LL << (n)) #define UNIQUE(v) \ v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと constexpr ll MOD = 1e9 + 7; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z; string S, T; ll ans = 0; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } signed main() { cin >> N >> K; int k = (N - 1) * (N - 2) / 2; if (K > k) { cout << -1 << endl; } else { cout << N - 1 + k - K << endl; REP(i, N - 1) { cout << 1 << " " << i + 2 << endl; } int cnt = k - K; REP(i, N - 1) FOR(j, i + 1, N - 1) { if (cnt-- == 0) return 1; cout << i + 2 << " " << j + 2 << endl; } } }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define dump(...) #endif #define endl "\n" #define ll long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define INF 2147483647 #define LLINF 9223372036854775807LL #define vi vector<int> #define vvi vector<vector<int>> #define pi pair<int, int> #define ALL(a) (a).begin(), (a).end() #define BIT(n) (1LL << (n)) #define UNIQUE(v) \ v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと constexpr ll MOD = 1e9 + 7; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z; string S, T; ll ans = 0; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } signed main() { cin >> N >> K; int k = (N - 1) * (N - 2) / 2; if (K > k) { cout << -1 << endl; } else { cout << N - 1 + k - K << endl; REP(i, N - 1) { cout << 1 << " " << i + 2 << endl; } int cnt = k - K; REP(i, N - 1) FOR(j, i + 1, N - 1) { if (cnt-- == 0) return 0; cout << i + 2 << " " << j + 2 << endl; } } }
replace
48
49
48
49
1
p02997
C++
Time Limit Exceeded
#include "bits/stdc++.h" int main() { int N, K; std::cin >> N >> K; int max = N * (N - 1) / 2 - (N - 1); int ans = -1; if (max < K) { std::cout << -1 << std::endl; return 0; } int M = N - 1 + max - K; std::cout << M << std::endl; for (int i = 2; i <= N; ++i) std::cout << 1 << " " << i << "\n"; for (int i = N - 1;;) { for (int j = 2; j <= N; ++j) { for (int k = j + 1; k <= N; ++k, ++i) { if (i >= M) return 0; std::cout << j << " " << k << "\n"; } } } }
#include "bits/stdc++.h" int main() { int N, K; std::cin >> N >> K; int max = N * (N - 1) / 2 - (N - 1); int ans = -1; if (max < K) { std::cout << -1 << std::endl; return 0; } int M = N - 1 + max - K; std::cout << M << std::endl; for (int i = 2; i <= N; ++i) std::cout << 1 << " " << i << "\n"; for (int i = N - 1; i < M;) { for (int j = 2; j < N && i < M; ++j) { for (int k = j + 1; k <= N && i < M; ++k, ++i) { std::cout << j << " " << k << "\n"; } } } }
replace
16
21
16
19
TLE
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define MAX 1000000 #define ll long long #define db double #define str string #define pb push_back #define For(i, s, e) for (ll i = (s); i < (e); i++) #define Forrev(i, s, e) for (ll i = (s); i >= (e); i--) #define all(v) v.begin(), v.end() #define vll vector<ll> #define vs vector<string> #define mapll map<ll, ll> #define pll pair<ll, ll> #define initialise(a, x) memset(a, x, sizeof(a)) #define maxheap priority_queue<ll> #define minheap priority_queue<ll, vector<ll>, greater<ll>> #define ff first #define ss second #define endl "\n" #define mp make_pair const ll mod = 1e9 + 7; ll takemod(ll a) { return ((a % mod) + mod) % mod; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll fast_exp(ll base, ll expo) { ll res = 1; while (expo > 0) { if (expo & 1) res = (res * base) % mod; base = (base * base) % mod; expo >>= 1; } return res; } ll modinv(ll a) { return takemod(fast_exp(takemod(a), mod - 2)); } signed main() { fast_cin(); #ifndef ONLINE_JUDGE freopen("C:/IO/in.txt", "r", stdin); freopen("C:/IO/out.txt", "w", stdout); #endif ll n, k; cin >> n >> k; if (k > ((n - 1) * (n - 2)) / 2) { cout << -1 << endl; return 0; } ll j = 1; while (((j + 1) * j) / 2 <= k) { j++; } vector<pll> p1; ll count = 0, prev = 0; j = 2; For(i, 2, n + 1) { if (count + prev <= k) { j = i + 1; p1.pb(mp(1, i)); count += prev; prev++; } else { break; } // cout<<count<<endl; } // cout<<count<<j<<endl; if (count < k) { p1.pb(mp(1, j)); ll diff = k - count; For(i, 2 + diff, j) { p1.pb(mp(i, j)); } j++; } if (j <= n) { For(i, j, n + 1) { For(l, 1, i) p1.pb(mp(l, i)); } } cout << p1.size() << endl; for (pll a : p1) cout << a.ff << " " << a.ss << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define MAX 1000000 #define ll long long #define db double #define str string #define pb push_back #define For(i, s, e) for (ll i = (s); i < (e); i++) #define Forrev(i, s, e) for (ll i = (s); i >= (e); i--) #define all(v) v.begin(), v.end() #define vll vector<ll> #define vs vector<string> #define mapll map<ll, ll> #define pll pair<ll, ll> #define initialise(a, x) memset(a, x, sizeof(a)) #define maxheap priority_queue<ll> #define minheap priority_queue<ll, vector<ll>, greater<ll>> #define ff first #define ss second #define endl "\n" #define mp make_pair const ll mod = 1e9 + 7; ll takemod(ll a) { return ((a % mod) + mod) % mod; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll fast_exp(ll base, ll expo) { ll res = 1; while (expo > 0) { if (expo & 1) res = (res * base) % mod; base = (base * base) % mod; expo >>= 1; } return res; } ll modinv(ll a) { return takemod(fast_exp(takemod(a), mod - 2)); } signed main() { fast_cin(); // #ifndef ONLINE_JUDGE // freopen("C:/IO/in.txt", "r", stdin); // freopen("C:/IO/out.txt", "w", stdout); // #endif ll n, k; cin >> n >> k; if (k > ((n - 1) * (n - 2)) / 2) { cout << -1 << endl; return 0; } ll j = 1; while (((j + 1) * j) / 2 <= k) { j++; } vector<pll> p1; ll count = 0, prev = 0; j = 2; For(i, 2, n + 1) { if (count + prev <= k) { j = i + 1; p1.pb(mp(1, i)); count += prev; prev++; } else { break; } // cout<<count<<endl; } // cout<<count<<j<<endl; if (count < k) { p1.pb(mp(1, j)); ll diff = k - count; For(i, 2 + diff, j) { p1.pb(mp(i, j)); } j++; } if (j <= n) { For(i, j, n + 1) { For(l, 1, i) p1.pb(mp(l, i)); } } cout << p1.size() << endl; for (pll a : p1) cout << a.ff << " " << a.ss << " "; cout << endl; return 0; }
replace
54
58
54
58
0
p02997
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>; #define chmax(x, y) x = max(x, y); int main() { int n, k; cin >> n >> k; int mx = (n - 1) * (n - 2) / 2; if (mx < k) { cout << -1 << endl; return 0; } vector<P> ans; rep(i, n - 1) { ans.push_back(P(i + 1, n)); } int add = mx - k; vector<P> edge; rep(i, n - 1) rep(j, i) ans.push_back(P(i + 1, j + 1)); rep(i, add) ans.push_back(edge[i]); cout << ans.size() << endl; rep(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; } 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>; #define chmax(x, y) x = max(x, y); int main() { int n, k; cin >> n >> k; int mx = (n - 1) * (n - 2) / 2; if (mx < k) { cout << -1 << endl; return 0; } vector<P> ans; rep(i, n - 1) { ans.push_back(P(i + 1, n)); } int add = mx - k; vector<P> edge; rep(i, n - 1) rep(j, i) edge.push_back(P(i + 1, j + 1)); rep(i, add) ans.push_back(edge[i]); cout << ans.size() << endl; rep(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; } return 0; }
replace
19
20
19
20
-11
p02997
Python
Runtime Error
from itertools import combinations n, k = map(int, input().split()) star = [] max_k = (n - 1) * (n - 2) // 2 delta = max_k - k cnt = 0 if k <= max_k: ans = [] for i in range(2, n + 1): star.append((1, i)) cnt += 1 if delta > 0: kumiawase = list(combinations(range(2, n), 2)) for j in range(delta): kumi = kumiawase[j] star.append(kumi) cnt += 1 print(cnt) for pair in star: print(*pair, sep=" ") else: print(-1)
from itertools import combinations n, k = map(int, input().split()) star = [] max_k = (n - 1) * (n - 2) // 2 delta = max_k - k cnt = 0 if k <= max_k: ans = [] for i in range(2, n + 1): star.append((1, i)) cnt += 1 if delta > 0: kumiawase = list(combinations(range(2, n + 1), 2)) for j in range(delta): kumi = kumiawase[j] star.append(kumi) cnt += 1 print(cnt) for pair in star: print(*pair, sep=" ") else: print(-1)
replace
14
15
14
15
0
p02997
Python
Runtime Error
n, k = map(int, input().split()) if k <= (n - 1) * (n - 2) // 2: raise Exception else: print(-1)
n, k = map(int, input().split()) if k <= (n - 1) * (n - 2) // 2: g = [0] * (n * n) for i in range(n * n): u = i // n v = i % n if u < v: g[i] = 1 i = 0 for _ in range(k): while g[i] == 0 or i % n == n - 1: i += 1 g[i] = 0 cnt = sum(g) print(cnt) for i, e in enumerate(g): if e: u = i // n + 1 v = i % n + 1 print(u, v) else: print(-1)
replace
3
4
3
24
1
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02997/Python/s244694894.py", line 4, in <module> raise Exception Exception
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 100000000 #define YJ 1145141919 #define INF_INT_MAX 2147483647 #define INF_LL 9223372036854775 #define INF_LL_MAX 9223372036854775807 #define EPS 1e-10 #define MOD 1000000007 #define MOD9 998244353 #define Pi acos(-1) #define LL long long #define ULL unsigned long long #define LD long double #define int long long using II = pair<int, int>; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) begin((a)), end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) const int MAX_N = 100; int N, K; vector<string> ans; void pushAns(int a, int b) { ans.push_back(to_string(a) + " " + to_string(b)); } void makeG(int base, int pos) { FOR(n, pos, N + 1) { FOR(m, base, n) { pushAns(n, m); } } } int S[MAX_N]; signed main() { cin >> N >> K; if (K == 0) { makeG(1, 1); cout << ans.size() << endl; REP(n, ans.size()) { cout << ans[n] << endl; } return 0; } int sumS = (N - 1) * (N - 2) / 2; if (K > sumS) { cout << -1 << endl; return 0; } FOR(n, 2, N + 1) { S[n] = n - 2; pushAns(1, n); } for (int n = N; 3 <= n; n--) { int p = 2; while (sumS > K && S[n] > 0) { S[n]--; sumS--; pushAns(n, p); p++; } } cout << ans.size() << endl; REP(n, ans.size()) { cout << ans[n] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 100000000 #define YJ 1145141919 #define INF_INT_MAX 2147483647 #define INF_LL 9223372036854775 #define INF_LL_MAX 9223372036854775807 #define EPS 1e-10 #define MOD 1000000007 #define MOD9 998244353 #define Pi acos(-1) #define LL long long #define ULL unsigned long long #define LD long double #define int long long using II = pair<int, int>; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) begin((a)), end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) const int MAX_N = 105; int N, K; vector<string> ans; void pushAns(int a, int b) { ans.push_back(to_string(a) + " " + to_string(b)); } void makeG(int base, int pos) { FOR(n, pos, N + 1) { FOR(m, base, n) { pushAns(n, m); } } } int S[MAX_N]; signed main() { cin >> N >> K; if (K == 0) { makeG(1, 1); cout << ans.size() << endl; REP(n, ans.size()) { cout << ans[n] << endl; } return 0; } int sumS = (N - 1) * (N - 2) / 2; if (K > sumS) { cout << -1 << endl; return 0; } FOR(n, 2, N + 1) { S[n] = n - 2; pushAns(1, n); } for (int n = N; 3 <= n; n--) { int p = 2; while (sumS > K && S[n] > 0) { S[n]--; sumS--; pushAns(n, p); p++; } } cout << ans.size() << endl; REP(n, ans.size()) { cout << ans[n] << endl; } return 0; }
replace
29
30
29
30
0
p02997
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define vi vector<int> #define vii vector<pair<int, int>> #define rep(i, a, b) for (int i = a; i < b; i++) #define repD(i, a, b) for (int i = a; i > b; i--) #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define all(a) a.begin(), a.end() #define MOD 1000000007 #define PI 3.14159265359 /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> using namespace __gnu_pbds; typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set; */ ///*X.find_by_order("index") /// X.order_of_key("key") #define deb(x) cerr << #x << " : " << x << "\n"; #ifndef local #define deb(x) ; #endif ///---------------------------------------------------------------------------------- int n, k; void solve() { cin >> n >> k; set<pii> adj; rep(i, 2, n + 1) adj.insert({1, i}); if (k > (n - 1) * (n - 2) / 2) { while (1) ; cout << -1; return; } int cur = (n - 1) * (n - 2) / 2; if (cur == k) { cout << adj.size() << "\n"; for (auto x : adj) cout << x.ff << " " << x.ss << "\n"; return; } rep(i, 2, n + 1) { rep(j, i + 1, n + 1) { cur--; adj.insert({i, j}); if (cur == k) { cout << adj.size() << "\n"; for (auto x : adj) cout << x.ff << " " << x.ss << "\n"; } } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef local /// freopen("input.txt","r",stdin); /// freopen("output.txt","w",stdout); #endif clock_t qwertyuiop = clock(); int t = 1; /// cin>>t; rep(a, 0, t) { /// cout<<"Case #"<<a+1<<": "; solve(); } #ifdef local { qwertyuiop = clock() - qwertyuiop; double time_taken = ((double)qwertyuiop) / CLOCKS_PER_SEC; cerr << fixed << setprecision(5) << "\n\nTime Taken : " << time_taken << " seconds\n"; } #endif }
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define vi vector<int> #define vii vector<pair<int, int>> #define rep(i, a, b) for (int i = a; i < b; i++) #define repD(i, a, b) for (int i = a; i > b; i--) #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define all(a) a.begin(), a.end() #define MOD 1000000007 #define PI 3.14159265359 /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> using namespace __gnu_pbds; typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set; */ ///*X.find_by_order("index") /// X.order_of_key("key") #define deb(x) cerr << #x << " : " << x << "\n"; #ifndef local #define deb(x) ; #endif ///---------------------------------------------------------------------------------- int n, k; void solve() { cin >> n >> k; set<pii> adj; rep(i, 2, n + 1) adj.insert({1, i}); if (k > (n - 1) * (n - 2) / 2) { cout << -1; return; } int cur = (n - 1) * (n - 2) / 2; if (cur == k) { cout << adj.size() << "\n"; for (auto x : adj) cout << x.ff << " " << x.ss << "\n"; return; } rep(i, 2, n + 1) { rep(j, i + 1, n + 1) { cur--; adj.insert({i, j}); if (cur == k) { cout << adj.size() << "\n"; for (auto x : adj) cout << x.ff << " " << x.ss << "\n"; } } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef local /// freopen("input.txt","r",stdin); /// freopen("output.txt","w",stdout); #endif clock_t qwertyuiop = clock(); int t = 1; /// cin>>t; rep(a, 0, t) { /// cout<<"Case #"<<a+1<<": "; solve(); } #ifdef local { qwertyuiop = clock() - qwertyuiop; double time_taken = ((double)qwertyuiop) / CLOCKS_PER_SEC; cerr << fixed << setprecision(5) << "\n\nTime Taken : " << time_taken << " seconds\n"; } #endif }
delete
44
46
44
44
TLE
p02997
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #include <cmath> typedef long long ll; using namespace std; vector<int> arr; stack<int> st; queue<int> qu; queue<pair<int, int>> qu2; priority_queue<int> pq; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, n) for (int i = 1; i <= (int)(n); i++) typedef set<int> set_t; typedef set<string> set_g; typedef complex<double> xy_t; #define mp make_pair double dot_product(xy_t a, xy_t b) { return (conj(a) * b).real(); } // 内積 double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } // 外積 xy_t projection(xy_t p, xy_t b) { return b * dot_product(p, b) / norm(b); } // 投影 // 対図形 int main() { int n, k; cin >> n >> k; int maxk = (n - 1) * (n - 2) / 2; if (maxk < k) { cout << -1 << endl; return 0; } vector<pair<int, int>> edges; rep(i, n - 1) { edges.push_back(mp(i + 1, n)); } vector<pair<int, int>> temp; rep(i, n - 1) { if (n == 2) continue; for (int j = i + 1; j < n - 2; j++) { temp.push_back(mp(i + 1, j + 1)); } } rep(i, maxk - k) { edges.push_back(temp[i]); } cout << edges.size() << endl; rep(i, edges.size()) { cout << get<0>(edges[i]) << " " << get<1>(edges[i]) << endl; } return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #include <cmath> typedef long long ll; using namespace std; vector<int> arr; stack<int> st; queue<int> qu; queue<pair<int, int>> qu2; priority_queue<int> pq; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, n) for (int i = 1; i <= (int)(n); i++) typedef set<int> set_t; typedef set<string> set_g; typedef complex<double> xy_t; #define mp make_pair double dot_product(xy_t a, xy_t b) { return (conj(a) * b).real(); } // 内積 double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } // 外積 xy_t projection(xy_t p, xy_t b) { return b * dot_product(p, b) / norm(b); } // 投影 // 対図形 int main() { int n, k; cin >> n >> k; int maxk = (n - 1) * (n - 2) / 2; if (maxk < k) { cout << -1 << endl; return 0; } vector<pair<int, int>> edges; rep(i, n - 1) { edges.push_back(mp(i + 1, n)); } vector<pair<int, int>> temp; rep(i, n - 1) { if (n == 2) continue; for (int j = i + 1; j < n - 1; j++) { temp.push_back(mp(i + 1, j + 1)); } } rep(i, maxk - k) { edges.push_back(temp[i]); } cout << edges.size() << endl; rep(i, edges.size()) { cout << get<0>(edges[i]) << " " << get<1>(edges[i]) << endl; } return 0; }
replace
38
39
38
39
0
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vector<vector<bool>>> vvvb; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<double> vd; typedef vector<vd> vdd; #define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i) #define REP(i, y) FOR(i, 0, y) #define RFOR(i, x, y) for (ll i = (ll)x; i >= (ll)y; --i) #define RREP(i, x) RFOR(i, x, 0) #define ALL(a) a.begin(), a.end() #define pb push_back #define debug_print(x...) \ cerr << "line " << __LINE__ << " : "; \ debug_print_in(x); template <typename First> void debug_print_in(First first) { cerr << first << endl; return; } template <typename First, typename... Rest> void debug_print_in(First first, Rest... rest) { cerr << first << " "; debug_print_in(rest...); return; } void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } template <typename First> void OUT(First first) { cout << first << endl; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest) { cout << first << " "; OUT(rest...); return; } template <class t, class u> void chmax(t &a, u b) { if (a < b) a = b; }; template <class t, class u> void chmin(t &a, u b) { if (a > b) a = b; }; int popcount(int t) { return __builtin_popcount(t); } // GCC int popcount(ll t) { return __builtin_popcountll(t); } // GCC template <typename T> void vec_print(vector<T> VEC) { REP(i, VEC.size()) { cerr << VEC[i] << " "; } cerr << endl; }; template <typename T> void mat_print(vector<vector<T>> MAT){ REP(i, MAT.size()){REP(j, MAT[i].size()){cerr << MAT[i][j] << " "; } cerr << endl; } } ; constexpr int INF = (1 << 30); constexpr ll INFLL = 1LL << 62; constexpr long double EPS = 1e-12; constexpr ll MOD = (ll)((1E+9) + 7); int main() { cin.tie(0); // cut the cin and cout (default, std::flush is performed after // std::cin) ios::sync_with_stdio( false); // cut the iostream and stdio (DON'T endl; BUT "\n";) ll N, K; IN(N, K); if (K > (N - 1) * (N - 2) / 2) { OUT(-1); return 0; } vll u, v; REP(i, N - 1) { u.pb(1); v.pb(i + 2); } ll count = (N - 1) * (N - 2) / 2; ll start = 2; ll end = 3; while (count > K) { u.pb(start); v.pb(end); end++; if (end > N) { start++; end = start + 1; } } printf("%lld\n", u.size()); REP(i, u.size()) { printf("%lld %lld\n", u[i], v[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vector<vector<bool>>> vvvb; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<double> vd; typedef vector<vd> vdd; #define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i) #define REP(i, y) FOR(i, 0, y) #define RFOR(i, x, y) for (ll i = (ll)x; i >= (ll)y; --i) #define RREP(i, x) RFOR(i, x, 0) #define ALL(a) a.begin(), a.end() #define pb push_back #define debug_print(x...) \ cerr << "line " << __LINE__ << " : "; \ debug_print_in(x); template <typename First> void debug_print_in(First first) { cerr << first << endl; return; } template <typename First, typename... Rest> void debug_print_in(First first, Rest... rest) { cerr << first << " "; debug_print_in(rest...); return; } void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } template <typename First> void OUT(First first) { cout << first << endl; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest) { cout << first << " "; OUT(rest...); return; } template <class t, class u> void chmax(t &a, u b) { if (a < b) a = b; }; template <class t, class u> void chmin(t &a, u b) { if (a > b) a = b; }; int popcount(int t) { return __builtin_popcount(t); } // GCC int popcount(ll t) { return __builtin_popcountll(t); } // GCC template <typename T> void vec_print(vector<T> VEC) { REP(i, VEC.size()) { cerr << VEC[i] << " "; } cerr << endl; }; template <typename T> void mat_print(vector<vector<T>> MAT){ REP(i, MAT.size()){REP(j, MAT[i].size()){cerr << MAT[i][j] << " "; } cerr << endl; } } ; constexpr int INF = (1 << 30); constexpr ll INFLL = 1LL << 62; constexpr long double EPS = 1e-12; constexpr ll MOD = (ll)((1E+9) + 7); int main() { cin.tie(0); // cut the cin and cout (default, std::flush is performed after // std::cin) ios::sync_with_stdio( false); // cut the iostream and stdio (DON'T endl; BUT "\n";) ll N, K; IN(N, K); if (K > (N - 1) * (N - 2) / 2) { OUT(-1); return 0; } vll u, v; REP(i, N - 1) { u.pb(1); v.pb(i + 2); } ll count = (N - 1) * (N - 2) / 2; ll start = 2; ll end = 3; while (count > K) { u.pb(start); v.pb(end); end++; if (end > N) { start++; end = start + 1; } count--; } printf("%lld\n", u.size()); REP(i, u.size()) { printf("%lld %lld\n", u[i], v[i]); } return 0; }
insert
119
119
119
120
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02997
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < n; ++i) #define rep(i, n) REP(i, 0, n) #define fst first #define snd second #define pb push_back #define ALL(x) x.begin(), x.end() #define EPS (1e-9) #define equals(a, b) (fabs((a) - (b)) < EPS) using namespace std; bool LT(double a, double b) { return !equals(a, b) && a < b; } bool LTE(double a, double b) { return equals(a, b) || a < b; } const string YES = ""; const string NO = ""; typedef long long ll; void solve() {} #define MAX 110 vector<int> G[MAX]; int fw[MAX][MAX]; bool check(int N, int K) { rep(i, N) rep(j, N) fw[i][j] = INT_MAX; rep(i, N) fw[i][i] = 0; rep(i, N) { rep(j, (int)G[i].size()) { fw[i][G[i][j]] = 1; fw[G[i][j]][i] = 1; } } rep(k, N) rep(i, N) rep(j, N) { if (fw[i][k] == INT_MAX || fw[k][j] == INT_MAX) continue; fw[i][j] = min(fw[i][j], fw[i][k] + fw[k][j]); } int cnt = 0; rep(i, N) { REP(j, i + 1, N) { if (fw[i][j] == 2) ++cnt; } } // cout << "cnt = " << cnt << ", K = " << K << endl; return cnt == K; } int main() { int N, K; cin >> N >> K; /* if( K < N - 2 ) { puts("-1"); return 0; } if( N > 2 && N == K ) { cout << N << endl; rep(i,N) { int s = i, t = ( i + 1 ) % N; cout << s + 1 << " " << t + 1 << endl; } return 0; } */ int n = N - 1; /* if( K > (int)(n*(n-1)/2) ) { puts("-1"); return 0; } */ REP(i, 1, N) { G[0].pb(i); } typedef pair<int, int> ii; int sum = n * (n - 1) / 2; int diff = sum - K; assert(diff >= 0); REP(i, 1, N) { REP(j, i + 1, N) { if (diff <= 0) break; G[i].pb(j); --diff; } if (diff <= 0) break; } set<ii> S; rep(i, N) { rep(j, (int)G[i].size()) { if (i < G[i][j]) { S.insert(ii(i, G[i][j])); } } } if (!check(N, K)) { puts("-1"); return 0; } cout << S.size() << endl; for (auto v : S) { cout << v.fst + 1 << " " << v.snd + 1 << endl; } return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < n; ++i) #define rep(i, n) REP(i, 0, n) #define fst first #define snd second #define pb push_back #define ALL(x) x.begin(), x.end() #define EPS (1e-9) #define equals(a, b) (fabs((a) - (b)) < EPS) using namespace std; bool LT(double a, double b) { return !equals(a, b) && a < b; } bool LTE(double a, double b) { return equals(a, b) || a < b; } const string YES = ""; const string NO = ""; typedef long long ll; void solve() {} #define MAX 110 vector<int> G[MAX]; int fw[MAX][MAX]; bool check(int N, int K) { rep(i, N) rep(j, N) fw[i][j] = INT_MAX; rep(i, N) fw[i][i] = 0; rep(i, N) { rep(j, (int)G[i].size()) { fw[i][G[i][j]] = 1; fw[G[i][j]][i] = 1; } } rep(k, N) rep(i, N) rep(j, N) { if (fw[i][k] == INT_MAX || fw[k][j] == INT_MAX) continue; fw[i][j] = min(fw[i][j], fw[i][k] + fw[k][j]); } int cnt = 0; rep(i, N) { REP(j, i + 1, N) { if (fw[i][j] == 2) ++cnt; } } // cout << "cnt = " << cnt << ", K = " << K << endl; return cnt == K; } int main() { int N, K; cin >> N >> K; /* if( K < N - 2 ) { puts("-1"); return 0; } if( N > 2 && N == K ) { cout << N << endl; rep(i,N) { int s = i, t = ( i + 1 ) % N; cout << s + 1 << " " << t + 1 << endl; } return 0; } */ int n = N - 1; /* if( K > (int)(n*(n-1)/2) ) { puts("-1"); return 0; } */ REP(i, 1, N) { G[0].pb(i); } typedef pair<int, int> ii; int sum = n * (n - 1) / 2; int diff = sum - K; REP(i, 1, N) { REP(j, i + 1, N) { if (diff <= 0) break; G[i].pb(j); --diff; } if (diff <= 0) break; } set<ii> S; rep(i, N) { rep(j, (int)G[i].size()) { if (i < G[i][j]) { S.insert(ii(i, G[i][j])); } } } if (!check(N, K)) { puts("-1"); return 0; } cout << S.size() << endl; for (auto v : S) { cout << v.fst + 1 << " " << v.snd + 1 << endl; } return 0; }
delete
80
81
80
80
0
p02997
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 = 1; i < (n); ++i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define maxs(a, b) a = max(a, b) #define mins(a, b) a = min(a, b) using namespace std; typedef long long ll; typedef pair<int, int> P; const int inf = 1001001001; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int mx = (n - 1) * (n - 2) / 2; if (mx < k) { cout << -1 << endl; return 0; } vector<P> ans; rep(i, n - 1) ans.push_back(P(i + 1, n)); int add = mx - k; vector<P> edge; rep(i, n - 1) rep(j, i) ans.push_back(P(i + 1, j + 1)); rep(i, add) ans.push_back(edge[i]); cout << ans.size() << endl; rep(i, ans.size()) { cout << ans[i].first << ' ' << ans[i].second << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i < (n); ++i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define maxs(a, b) a = max(a, b) #define mins(a, b) a = min(a, b) using namespace std; typedef long long ll; typedef pair<int, int> P; const int inf = 1001001001; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int mx = (n - 1) * (n - 2) / 2; if (mx < k) { cout << -1 << endl; return 0; } vector<P> ans; rep(i, n - 1) ans.push_back(P(i + 1, n)); int add = mx - k; vector<P> edge; rep(i, n - 1) rep(j, i) edge.push_back(P(i + 1, j + 1)); rep(i, add) ans.push_back(edge[i]); cout << ans.size() << endl; rep(i, ans.size()) { cout << ans[i].first << ' ' << ans[i].second << endl; } return 0; }
replace
27
28
27
28
-11
p02997
C++
Runtime Error
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n, k; cin >> n >> k; int num = (n - 1) * (n - 2); num /= 2; if (k > num) { cout << -1 << endl; return 0; } // 辺の数 int m = (n - 1) + (num - k); pair<int, int> p[m]; for (int i = 1; i < n; i++) { p[i - 1].first = 1; p[i - 1].second = i + 1; } int idx = n - 1; for (int i = 1; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { p[idx].first = i + 1; p[idx].second = j + 1; idx++; if (idx == m) { cout << m << endl; for (int l = 0; l < m; l++) { cout << p[l].first << ' ' << p[l].second << endl; } return 0; } } } }
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n, k; cin >> n >> k; int num = (n - 1) * (n - 2); num /= 2; if (k > num) { cout << -1 << endl; return 0; } // 辺の数 int m = (n - 1) + (num - k); pair<int, int> p[m]; for (int i = 1; i < n; i++) { p[i - 1].first = 1; p[i - 1].second = i + 1; } int idx = n - 1; if (idx == m) { cout << m << endl; for (int l = 0; l < m; l++) { cout << p[l].first << ' ' << p[l].second << endl; } return 0; } for (int i = 1; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { p[idx].first = i + 1; p[idx].second = j + 1; idx++; if (idx == m) { cout << m << endl; for (int l = 0; l < m; l++) { cout << p[l].first << ' ' << p[l].second << endl; } return 0; } } } }
insert
26
26
26
33
0
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << ": " << arg1 << std::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...); } #else #define trace(...) #endif #define boost \ ios::sync_with_stdio(0); \ cin.tie(0); #define int long long const int N = 1e5 + 10; const int mod = 1e9 + 7; int n, k; int32_t main() { boost; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // code cin >> n >> k; int x = ((n - 1) * (n - 2)) / 2; if (k > x) { cout << -1; return 0; } set<pair<int, int>> ans; int diff = (n * (n - 1)) / 2 - k; // trace(diff); for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { int a = i, b = j; if (a > b) swap(a, b); ans.insert({a, b}); diff -= 1; if (diff == 0) break; } if (diff == 0) break; } cout << ans.size() << "\n"; for (auto i : ans) { cout << i.first << " " << i.second << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << ": " << arg1 << std::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...); } #else #define trace(...) #endif #define boost \ ios::sync_with_stdio(0); \ cin.tie(0); #define int long long const int N = 1e5 + 10; const int mod = 1e9 + 7; int n, k; int32_t main() { boost; // code cin >> n >> k; int x = ((n - 1) * (n - 2)) / 2; if (k > x) { cout << -1; return 0; } set<pair<int, int>> ans; int diff = (n * (n - 1)) / 2 - k; // trace(diff); for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { int a = i, b = j; if (a > b) swap(a, b); ans.insert({a, b}); diff -= 1; if (diff == 0) break; } if (diff == 0) break; } cout << ans.size() << "\n"; for (auto i : ans) { cout << i.first << " " << i.second << "\n"; } return 0; }
delete
36
40
36
36
0
p02997
C++
Time Limit Exceeded
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define endl "\n" #define sz(x) ((ll)(x).size()) #define pb push_back #define all(x) (x).begin(), (x).end() #define prt(x) cout << (x) #define prtl(x) cout << (x) << endl #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i > b; i--) #define mp(a, b) make_pair(a, b) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define debug(v) cout << #v << ": " << v << endl; using namespace std; using vi = vector<int>; using vll = vector<long long int>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvi = vector<vector<int>>; using vvll = vector<vector<long long int>>; using vvc = vector<vector<char>>; using ll = long long int; using P = pair<long long int, long long int>; using Map = map<long long int, long long int>; ll INF = 1LL << 60; ll M = 1000000007; int main() { ll N, K; cin >> N >> K; if (K > (N - 1) * (N - 2) / 2) { prtl(-1); return 0; } ll n = 0; bool t = true; while (t) { ll c = n * (n - 1) / 2; n++; ll d = n * (n - 1) / 2; if (c < K && d >= K) { t = false; } } ll r = n * (n - 1) / 2 - K; vector<P> ans(0); rep(i, 0, n) { ans.emplace_back(mp(1, i + 2)); } rep(i, 0, r) { ans.emplace_back(mp(i + 2, i + 3)); } rep(i, n + 2, N + 1) { rep(j, 1, i) { ans.emplace_back(mp(i, j)); } } prtl(sz(ans)); for (auto x : ans) { prt(x.first); prt(" "); prtl(x.second); } }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define endl "\n" #define sz(x) ((ll)(x).size()) #define pb push_back #define all(x) (x).begin(), (x).end() #define prt(x) cout << (x) #define prtl(x) cout << (x) << endl #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i > b; i--) #define mp(a, b) make_pair(a, b) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define debug(v) cout << #v << ": " << v << endl; using namespace std; using vi = vector<int>; using vll = vector<long long int>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvi = vector<vector<int>>; using vvll = vector<vector<long long int>>; using vvc = vector<vector<char>>; using ll = long long int; using P = pair<long long int, long long int>; using Map = map<long long int, long long int>; ll INF = 1LL << 60; ll M = 1000000007; int main() { ll N, K; cin >> N >> K; if (K > (N - 1) * (N - 2) / 2) { prtl(-1); return 0; } if (K == 0) { vector<P> ans(0); rep(i, 2, N + 1) { rep(j, 1, i) { ans.emplace_back(mp(i, j)); } } prtl(sz(ans)); for (auto x : ans) { prt(x.first); prt(" "); prtl(x.second); } return 0; } ll n = 0; bool t = true; while (t) { ll c = n * (n - 1) / 2; n++; ll d = n * (n - 1) / 2; if (c < K && d >= K) { t = false; } } ll r = n * (n - 1) / 2 - K; vector<P> ans(0); rep(i, 0, n) { ans.emplace_back(mp(1, i + 2)); } rep(i, 0, r) { ans.emplace_back(mp(i + 2, i + 3)); } rep(i, n + 2, N + 1) { rep(j, 1, i) { ans.emplace_back(mp(i, j)); } } prtl(sz(ans)); for (auto x : ans) { prt(x.first); prt(" "); prtl(x.second); } }
insert
36
36
36
49
TLE
p02997
Python
Runtime Error
N, K = map(int, input().split()) if K > (N - 1)(N - 2) // 2: print(-1) else: M = N * (N - 1) // 2 - K cnt = 0 ans = [] for i in range(N - 1): for j in range(i + 1, N): ans.append((i + 1, j + 1)) cnt += 1 if M == cnt: break else: continue break print(M) for edge in ans: print(*edge)
N, K = map(int, input().split()) if K > (N - 1) * (N - 2) // 2: print(-1) else: M = N * (N - 1) // 2 - K cnt = 0 ans = [] for i in range(N - 1): for j in range(i + 1, N): ans.append((i + 1, j + 1)) cnt += 1 if M == cnt: break else: continue break print(M) for edge in ans: print(*edge)
replace
2
3
2
3
TypeError: 'int' object is not callable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02997/Python/s559992185.py", line 3, in <module> if K > (N - 1)(N - 2) // 2: TypeError: 'int' object is not callable
p02997
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 5e18; int main() { ll n; cin >> n; ll k; cin >> k; ll lim = n * (n - 1) / 2 - (n - 1); cout << lim - k + n - 1 << endl; for (ll i = 2; i <= n; i++) { cout << 1 << " " << i << endl; } ll i = 2, j = 3; ll cnt = lim - k; while (cnt--) { cout << i << " " << j << endl; if (j < n) j++; else i++, j = i + 1; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 5e18; int main() { ll n; cin >> n; ll k; cin >> k; ll lim = n * (n - 1) / 2 - (n - 1); if (lim < k) { cout << -1 << endl; return 0; } cout << lim - k + n - 1 << endl; for (ll i = 2; i <= n; i++) { cout << 1 << " " << i << endl; } ll i = 2, j = 3; ll cnt = lim - k; while (cnt--) { cout << i << " " << j << endl; if (j < n) j++; else i++, j = i + 1; } }
insert
16
16
16
20
TLE
p02997
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define all(x) (x).begin(), (x).end() using namespace std; const int INF = 1145141919, MOD = 1e9 + 7; const int64_t LINF = 8931145141919364364, LMOD = 998244353; // const int dy[]={0,-1,0,1,1,-1,-1,1}; // const int dx[]={1,0,-1,0,1,1,-1,-1}; int main() { int n, k; cin >> n >> k; int maxi = (n - 2) * (n - 1) / 2; if (k > maxi) { cout << -1 << endl; return 0; } vector<int> u, v; for (int i = 2; i <= n; i++) { u.push_back(1); v.push_back(i); } int nn = maxi - k; int from = 2; while (1) { bool flg = 0; for (int to = from + 1; to <= n; to++) { u.push_back(from); v.push_back(to); nn--; if (nn == 0) { flg = 1; break; } } from++; if (flg) break; } int m = u.size(); cout << m << endl; rep(i, m) { cout << u[i] << " " << v[i] << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define all(x) (x).begin(), (x).end() using namespace std; const int INF = 1145141919, MOD = 1e9 + 7; const int64_t LINF = 8931145141919364364, LMOD = 998244353; // const int dy[]={0,-1,0,1,1,-1,-1,1}; // const int dx[]={1,0,-1,0,1,1,-1,-1}; int main() { int n, k; cin >> n >> k; int maxi = (n - 2) * (n - 1) / 2; if (k > maxi) { cout << -1 << endl; return 0; } vector<int> u, v; for (int i = 2; i <= n; i++) { u.push_back(1); v.push_back(i); } int nn = maxi - k; int from = 2; while (nn > 0) { bool flg = 0; for (int to = from + 1; to <= n; to++) { u.push_back(from); v.push_back(to); nn--; if (nn == 0) { flg = 1; break; } } from++; if (flg) break; } int m = u.size(); cout << m << endl; rep(i, m) { cout << u[i] << " " << v[i] << endl; } return 0; }
replace
24
25
24
25
TLE
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, K; cin >> N >> K; if (K > ((N - 1) * (N - 2)) / 2) return -1; vector<pair<int, int>> ret; for (int i = 2; i <= N; i++) { ret.push_back(make_pair(1, i)); } int cnt = ((N - 1) * (N - 2)) / 2 - K; for (int i = 2; i <= N; i++) { for (int j = i + 1; j <= N; j++) { if (cnt) { ret.push_back(make_pair(i, j)); cnt--; } else break; } if (!cnt) break; } cout << ret.size() << endl; for (int i = 0; i < ret.size(); i++) { cout << ret[i].first << ' ' << ret[i].second << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, K; cin >> N >> K; if (N == 2) { if (K == 0) cout << 1 << endl << 1 << ' ' << 2 << endl; else cout << -1 << endl; return 0; } if (K > ((N - 1) * (N - 2)) / 2) { cout << -1 << endl; return 0; } vector<pair<int, int>> ret; for (int i = 2; i <= N; i++) { ret.push_back(make_pair(1, i)); } int cnt = ((N - 1) * (N - 2)) / 2 - K; for (int i = 2; i <= N; i++) { for (int j = i + 1; j <= N; j++) { if (cnt) { ret.push_back(make_pair(i, j)); cnt--; } else break; } if (!cnt) break; } cout << ret.size() << endl; for (int i = 0; i < ret.size(); i++) { cout << ret[i].first << ' ' << ret[i].second << endl; } }
replace
7
9
7
19
0
p02997
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 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 <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1 << 30; const ll INFL = 1LL << 60; const ll mod = 1000000007; int main() { int n, k; cin >> n >> k; if (k > (n - 1) * (n - 2) / 2) { cout << -1 << endl; return 0; } assert(n == 0); }
#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 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 <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1 << 30; const ll INFL = 1LL << 60; const ll mod = 1000000007; int main() { int n, k; cin >> n >> k; if (k > (n - 1) * (n - 2) / 2) { cout << -1 << endl; return 0; } int l = (n - 1) * (n - 2) / 2; l -= k; vector<pair<int, int>> v; REP(i, n - 1) { v.push_back({1, i + 2}); } while (l) { FOR(i, 2, n) { FOR(j, i + 1, n + 1) { l--; v.push_back({i, j}); if (l == 0) break; } if (l == 0) break; } break; } cout << v.size() << endl; REP(i, v.size()) { cout << v[i].first << ' ' << v[i].second << endl; } }
replace
47
48
47
71
-6
d03add5e-89f1-4bbc-8ed4-d282d8b838e2.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02997/C++/s490993811.cpp:39: int main(): Assertion `n == 0' failed.
p02997
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int count = 0; vector<vector<int>> G(N); int m = (N - 2) * (N - 1) / 2; if (K > m) { cout << -1 << endl; return 0; } for (int i = 1; i < N; i++) G[0].push_back(i); int n = m - K; for (int i = 0; i < n; i++) G[i + 1].push_back(i + 2); cout << N - 1 + n << endl; for (int i = 0; i < G.size(); i++) { for (int j = 0; j < G[i].size(); j++) { cout << i + 1 << " " << G[i][j] + 1 << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int count = 0; vector<vector<int>> G(N); int m = (N - 2) * (N - 1) / 2; if (K > m) { cout << -1 << endl; return 0; } for (int i = 1; i < N; i++) G[0].push_back(i); int n = m - K; int cnt = 0; for (int i = 1; i < N - 1; i++) { if (cnt >= n) break; for (int j = i + 1; j < N; j++) { if (cnt >= n) break; G[i].push_back(j); cnt++; } } cout << N - 1 + n << endl; for (int i = 0; i < G.size(); i++) { for (int j = 0; j < G[i].size(); j++) { cout << i + 1 << " " << G[i][j] + 1 << endl; } } }
replace
18
21
18
29
0
p02997
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define M 1000000007 #define mod 998244353 #define mp(x, y) make_pair(x, y) #define pb(x) push_back(x) #define pi pair<ll, ll> using namespace std; const ll N = 250001; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; if (n == 2) { exit(1); if (k != 1) { cout << "-1"; } else { cout << "1" << endl; cout << "1 2"; } return (0); } ll lol = ((n - 1) * (n - 2)) / 2; if (k > lol) { cout << "-1"; return (0); } set<pi> ans; for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { ans.insert(mp(i, j)); } } while (k--) { set<pi>::iterator it = ans.begin(); while (it->second == n) { advance(it, 1); } ans.erase(it); } cout << ans.size() << endl; for (auto x : ans) { cout << x.first << " " << x.second << endl; } return (0); }
#include <bits/stdc++.h> #define ll long long int #define M 1000000007 #define mod 998244353 #define mp(x, y) make_pair(x, y) #define pb(x) push_back(x) #define pi pair<ll, ll> using namespace std; const ll N = 250001; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; ll lol = ((n - 1) * (n - 2)) / 2; if (k > lol) { cout << "-1"; return (0); } set<pi> ans; for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { ans.insert(mp(i, j)); } } while (k--) { set<pi>::iterator it = ans.begin(); while (it->second == n) { advance(it, 1); } ans.erase(it); } cout << ans.size() << endl; for (auto x : ans) { cout << x.first << " " << x.second << endl; } return (0); }
delete
17
28
17
17
0
p02997
C++
Time Limit Exceeded
// need #include <algorithm> #include <iostream> // data structure #include <bitset> #include <complex> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> // #include <deque> #include <array> #include <unordered_map> #include <unordered_set> #include <valarray> // stream // #include <istream> #include <sstream> // #include <ostream> #include <fstream> // etc #include <cassert> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <random> // input #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define VAR(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...) \ std::vector<type> __VA_ARGS__; \ MACRO_VEC_ROW_Init(n, __VA_ARGS__); \ for (int w_ = 0; w_ < n; ++w_) { \ MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \ } template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); } template <typename First, typename... Rest> void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; } template <typename First, typename... Rest> void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(type, c, m, n) \ std::vector<std::vector<type>> c(m, std::vector<type>(n)); \ for (auto &R : c) \ for (auto &w : R) \ std::cin >> w; // output #define OUT(dist) std::cout << (dist); #define FOUT(n, dist) std::cout << std::fixed << std::setprecision(n) << (dist); #define SOUT(n, c, dist) std::cout << std::setw(n) << std::setfill(c) << (dist); #define SP std::cout << " "; #define TAB std::cout << "\t"; #define BR std::cout << "\n"; #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define ENDL std::cout << std::endl; #define FLUSH std::cout << std::flush; #define SHOW(dist) \ { std::cerr << #dist << "\t:" << (dist) << "\n"; } #define SHOWVECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOWVECTOR2(v) \ { \ std::cerr << #v << "\t:\n"; \ for (const auto &xxx : v) { \ for (const auto &yyy : xxx) { \ std::cerr << yyy << " "; \ } \ std::cerr << "\n"; \ } \ } #define SHOWQUEUE(a) \ { \ auto tmp(a); \ std::cerr << #a << "\t:"; \ while (!tmp.empty()) { \ std::cerr << tmp.front() << " "; \ tmp.pop(); \ } \ std::cerr << "\n"; \ } // utility #define ALL(a) (a).begin(), (a).end() #define FOR(w, a, n) for (int w = (a); w < (n); ++w) #define RFOR(w, a, n) for (int w = (n)-1; w >= (a); --w) #define REP(w, n) for (int w = 0; w < int(n); ++w) #define RREP(w, n) for (int w = int(n) - 1; w >= 0; --w) #define IN(a, x, b) (a <= x && x < b) template <class T> inline T CHMAX(T &a, const T b) { return a = (a < b) ? b : a; } template <class T> inline T CHMIN(T &a, const T b) { return a = (b < a) ? b : a; } #define EXCEPTION(msg) \ throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \ std::to_string(__LINE__) + " lines ]" #define TRY(cond, msg) \ try { \ if (cond) \ EXCEPTION(msg); \ } catch (std::string s) { \ std::cerr << s << std::endl; \ } void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)) .count(); std::cerr << res / (1.0e9) << "s\n"; } // test template <class T> using V = std::vector<T>; template <class T> using VV = V<V<T>>; template <typename S, typename T> std::ostream &operator<<(std::ostream &os, std::pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define random_shuffle "USE std::shuffle!"; // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; using PAIR = std::pair<int, int>; using PAIRLL = std::pair<ll, ll>; constexpr int INFINT = (1 << 30) - 1; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double EPS = 1e-10; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template <class T, size_t N> void FILL(T (&a)[N], const T &val) { for (auto &x : a) x = val; } template <class ARY, size_t N, size_t M, class T> void FILL(ARY (&a)[N][M], const T &val) { for (auto &b : a) FILL(b, val); } template <class T> void FILL(std::vector<T> &a, const T &val) { for (auto &x : a) x = val; } template <class ARY, class T> void FILL(std::vector<std::vector<ARY>> &a, const T &val) { for (auto &b : a) FILL(b, val); } // ------------>8------------------------------------->8------------ void calc(int n) { V<PAIR> e; REP(i, n) FOR(j, i + 1, n) e.emplace_back(i, j); std::map<int, int> map; REP(bit, 1 << e.size()) { VV<int> g(n, V<int>(n, INFINT)); V<PAIR> ee; REP(i, e.size()) { if (bit & 1 << i) { g[e[i].first][e[i].second] = 1; g[e[i].second][e[i].first] = 1; ee.emplace_back(e[i]); } } REP(k, n) REP(i, n) REP(j, n) CHMIN(g[i][j], g[i][k] + g[k][j]); int cnt = 0; REP(i, n) FOR(j, i + 1, n) cnt += g[i][j] == 2; ++map[cnt]; } SHOWVECTOR(map); } signed main() { INIT; VAR(int, n, k); if (k > (n - 1) * (n - 2) / 2) { OUT(-1) BR; return 0; } VV<bool> g(n, V<bool>(n, 0)); V<PAIR> ans; FOR(i, 1, n) { ans.emplace_back(0, i); g[0][i] = g[i][0] = true; } int i = 1; REP(_, (n - 1) * (n - 2) / 2 - k) { [&] { while (true) { int j = i + 2; while (j < n && g[i][j]) ++j; if (j >= n) { ++i; continue; } ans.emplace_back(i, j); g[i][j] = g[j][i] = true; return; } }(); } OUT(ans.size()) BR; REP(i, ans.size()) { OUT(ans[i].first + 1) SP OUT(ans[i].second + 1) BR; } return 0; }
// need #include <algorithm> #include <iostream> // data structure #include <bitset> #include <complex> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> // #include <deque> #include <array> #include <unordered_map> #include <unordered_set> #include <valarray> // stream // #include <istream> #include <sstream> // #include <ostream> #include <fstream> // etc #include <cassert> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <random> // input #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define VAR(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...) \ std::vector<type> __VA_ARGS__; \ MACRO_VEC_ROW_Init(n, __VA_ARGS__); \ for (int w_ = 0; w_ < n; ++w_) { \ MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \ } template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); } template <typename First, typename... Rest> void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; } template <typename First, typename... Rest> void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(type, c, m, n) \ std::vector<std::vector<type>> c(m, std::vector<type>(n)); \ for (auto &R : c) \ for (auto &w : R) \ std::cin >> w; // output #define OUT(dist) std::cout << (dist); #define FOUT(n, dist) std::cout << std::fixed << std::setprecision(n) << (dist); #define SOUT(n, c, dist) std::cout << std::setw(n) << std::setfill(c) << (dist); #define SP std::cout << " "; #define TAB std::cout << "\t"; #define BR std::cout << "\n"; #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define ENDL std::cout << std::endl; #define FLUSH std::cout << std::flush; #define SHOW(dist) \ { std::cerr << #dist << "\t:" << (dist) << "\n"; } #define SHOWVECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOWVECTOR2(v) \ { \ std::cerr << #v << "\t:\n"; \ for (const auto &xxx : v) { \ for (const auto &yyy : xxx) { \ std::cerr << yyy << " "; \ } \ std::cerr << "\n"; \ } \ } #define SHOWQUEUE(a) \ { \ auto tmp(a); \ std::cerr << #a << "\t:"; \ while (!tmp.empty()) { \ std::cerr << tmp.front() << " "; \ tmp.pop(); \ } \ std::cerr << "\n"; \ } // utility #define ALL(a) (a).begin(), (a).end() #define FOR(w, a, n) for (int w = (a); w < (n); ++w) #define RFOR(w, a, n) for (int w = (n)-1; w >= (a); --w) #define REP(w, n) for (int w = 0; w < int(n); ++w) #define RREP(w, n) for (int w = int(n) - 1; w >= 0; --w) #define IN(a, x, b) (a <= x && x < b) template <class T> inline T CHMAX(T &a, const T b) { return a = (a < b) ? b : a; } template <class T> inline T CHMIN(T &a, const T b) { return a = (b < a) ? b : a; } #define EXCEPTION(msg) \ throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \ std::to_string(__LINE__) + " lines ]" #define TRY(cond, msg) \ try { \ if (cond) \ EXCEPTION(msg); \ } catch (std::string s) { \ std::cerr << s << std::endl; \ } void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)) .count(); std::cerr << res / (1.0e9) << "s\n"; } // test template <class T> using V = std::vector<T>; template <class T> using VV = V<V<T>>; template <typename S, typename T> std::ostream &operator<<(std::ostream &os, std::pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define random_shuffle "USE std::shuffle!"; // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; using PAIR = std::pair<int, int>; using PAIRLL = std::pair<ll, ll>; constexpr int INFINT = (1 << 30) - 1; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double EPS = 1e-10; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template <class T, size_t N> void FILL(T (&a)[N], const T &val) { for (auto &x : a) x = val; } template <class ARY, size_t N, size_t M, class T> void FILL(ARY (&a)[N][M], const T &val) { for (auto &b : a) FILL(b, val); } template <class T> void FILL(std::vector<T> &a, const T &val) { for (auto &x : a) x = val; } template <class ARY, class T> void FILL(std::vector<std::vector<ARY>> &a, const T &val) { for (auto &b : a) FILL(b, val); } // ------------>8------------------------------------->8------------ void calc(int n) { V<PAIR> e; REP(i, n) FOR(j, i + 1, n) e.emplace_back(i, j); std::map<int, int> map; REP(bit, 1 << e.size()) { VV<int> g(n, V<int>(n, INFINT)); V<PAIR> ee; REP(i, e.size()) { if (bit & 1 << i) { g[e[i].first][e[i].second] = 1; g[e[i].second][e[i].first] = 1; ee.emplace_back(e[i]); } } REP(k, n) REP(i, n) REP(j, n) CHMIN(g[i][j], g[i][k] + g[k][j]); int cnt = 0; REP(i, n) FOR(j, i + 1, n) cnt += g[i][j] == 2; ++map[cnt]; } SHOWVECTOR(map); } signed main() { INIT; VAR(int, n, k); if (k > (n - 1) * (n - 2) / 2) { OUT(-1) BR; return 0; } VV<bool> g(n, V<bool>(n, 0)); V<PAIR> ans; FOR(i, 1, n) { ans.emplace_back(0, i); g[0][i] = g[i][0] = true; } int i = 1; REP(_, (n - 1) * (n - 2) / 2 - k) { [&] { while (true) { int j = i + 1; while (j < n && g[i][j]) ++j; if (j >= n) { ++i; continue; } ans.emplace_back(i, j); g[i][j] = g[j][i] = true; return; } }(); } OUT(ans.size()) BR; REP(i, ans.size()) { OUT(ans[i].first + 1) SP OUT(ans[i].second + 1) BR; } return 0; }
replace
233
234
233
234
TLE
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ub upper_bound #define lb upper_bound #define mp make_pair #define F first #define S second #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) #define ve vector #define vi vector<int> #define vp vector<pair<int, int>> #define vvi vector<vector<int>> typedef long long ll; const ll INF = LLONG_MAX - 100; const ll mod = 1e9 + 7; const int MAX_N = 2e5 + 5; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; vector<ll> prime; int fac[MAX_N], inv[MAX_N]; template <class T = ll> T in() { T x; cin >> x; return (x); } void DEBUG(vector<int> a) { for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; } ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; } return a; } ll LCM(ll a, ll b) { return a * b / GCD(a, b); } ll POW(ll a, ll b, bool usemod = true) { ll c = 1LL; while (b > 0) { if (b & 1LL) { if (!usemod) c *= a; else c = a * c % mod; } if (!usemod) a *= a; else a = a * a % mod; b >>= 1LL; } return c; } void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i % mod; } for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } } ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod) * inv[n - r] % mod; } void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; } for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } } template <typename T> T chmin(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T chmax(T &a, T b) { if (a < b) a = b; return b; } class UnionFind { private: vector<ll> par; public: UnionFind(int N) { par = vector<int>(N, -1); } int find(int x); ll size(int x); void unite(int x, int y); bool same(int x, int y); }; int UnionFind::find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } ll UnionFind::size(int x) { return -par[find(x)]; } void UnionFind::unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; // 大きい方に小さい方をくっ付ける if (size(x) < size(y)) swap(x, y); par[x] += par[y]; par[y] = x; } bool UnionFind::same(int x, int y) { x = find(x); y = find(y); return x == y; } int MAX = 11000; bool solve() { int n; cin >> n; UnionFind uf(MAX * 2); REP(i, n) { int x, y; cin >> x >> y; uf.unite(x, y + MAX); } map<int, int> mx, my; REP(i, MAX) mx[uf.find(i)]++; FOR(i, MAX, 2 * MAX) my[uf.find(i)]++; int ans = 0; REP(i, 2 * MAX) ans += mx[i] * my[i]; ans -= n; cout << ans << endl; } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ub upper_bound #define lb upper_bound #define mp make_pair #define F first #define S second #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) #define ve vector #define vi vector<int> #define vp vector<pair<int, int>> #define vvi vector<vector<int>> typedef long long ll; const ll INF = LLONG_MAX - 100; const ll mod = 1e9 + 7; const int MAX_N = 2e5 + 5; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; vector<ll> prime; int fac[MAX_N], inv[MAX_N]; template <class T = ll> T in() { T x; cin >> x; return (x); } void DEBUG(vector<int> a) { for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; } ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; } return a; } ll LCM(ll a, ll b) { return a * b / GCD(a, b); } ll POW(ll a, ll b, bool usemod = true) { ll c = 1LL; while (b > 0) { if (b & 1LL) { if (!usemod) c *= a; else c = a * c % mod; } if (!usemod) a *= a; else a = a * a % mod; b >>= 1LL; } return c; } void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i % mod; } for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } } ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod) * inv[n - r] % mod; } void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; } for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } } template <typename T> T chmin(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T chmax(T &a, T b) { if (a < b) a = b; return b; } class UnionFind { private: vector<ll> par; public: UnionFind(int N) { par = vector<int>(N, -1); } int find(int x); ll size(int x); void unite(int x, int y); bool same(int x, int y); }; int UnionFind::find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } ll UnionFind::size(int x) { return -par[find(x)]; } void UnionFind::unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; // 大きい方に小さい方をくっ付ける if (size(x) < size(y)) swap(x, y); par[x] += par[y]; par[y] = x; } bool UnionFind::same(int x, int y) { x = find(x); y = find(y); return x == y; } int MAX = 110000; bool solve() { int n; cin >> n; UnionFind uf(MAX * 2); REP(i, n) { int x, y; cin >> x >> y; uf.unite(x, y + MAX); } map<int, int> mx, my; REP(i, MAX) mx[uf.find(i)]++; FOR(i, MAX, 2 * MAX) my[uf.find(i)]++; int ans = 0; REP(i, 2 * MAX) ans += mx[i] * my[i]; ans -= n; cout << ans << endl; } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
replace
142
143
142
143
0
p02998
C++
Runtime Error
#include <algorithm> #include <functional> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> X(N), Y(N); for (int i = 0; i < N; ++i) { cin >> X[i] >> Y[i]; } vector<int> gx = X, gy = Y; sort(gx.begin(), gx.end()); gx.erase(unique(gx.begin(), gx.end()), gx.end()); sort(gy.begin(), gy.end()); gy.erase(unique(gy.begin(), gy.end()), gy.end()); int sx = gx.size(), sy = gy.size(); vector<vector<int>> G(sx + sy); for (int i = 0; i < N; ++i) { int px = lower_bound(gx.begin(), gx.end(), X[i]) - gx.begin(); int py = lower_bound(gy.begin(), gy.end(), Y[i]) - gy.begin(); G[px].push_back(py + sy); G[py + sy].push_back(px); } vector<bool> vis(sx + sy, false); int cx = 0, cy = 0; function<void(int)> dfs = [&](int pos) { vis[pos] = true; if (pos < sx) ++cx; else ++cy; for (int i : G[pos]) { if (vis[i]) continue; dfs(i); } }; long long ans = 0; for (int i = 0; i < sx + sy; ++i) { if (!vis[i]) { cx = 0, cy = 0; dfs(i); ans += 1LL * cx * cy; } } cout << ans - N << endl; return 0; }
#include <algorithm> #include <functional> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> X(N), Y(N); for (int i = 0; i < N; ++i) { cin >> X[i] >> Y[i]; } vector<int> gx = X, gy = Y; sort(gx.begin(), gx.end()); gx.erase(unique(gx.begin(), gx.end()), gx.end()); sort(gy.begin(), gy.end()); gy.erase(unique(gy.begin(), gy.end()), gy.end()); int sx = gx.size(), sy = gy.size(); vector<vector<int>> G(sx + sy); for (int i = 0; i < N; ++i) { int px = lower_bound(gx.begin(), gx.end(), X[i]) - gx.begin(); int py = lower_bound(gy.begin(), gy.end(), Y[i]) - gy.begin(); G[px].push_back(py + sx); G[py + sx].push_back(px); } vector<bool> vis(sx + sy, false); int cx = 0, cy = 0; function<void(int)> dfs = [&](int pos) { vis[pos] = true; if (pos < sx) ++cx; else ++cy; for (int i : G[pos]) { if (vis[i]) continue; dfs(i); } }; long long ans = 0; for (int i = 0; i < sx + sy; ++i) { if (!vis[i]) { cx = 0, cy = 0; dfs(i); ans += 1LL * cx * cy; } } cout << ans - N << endl; return 0; }
replace
22
24
22
24
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> #include <random> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; #define int ll // #define int __int128 // #define ll __int128 typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<short> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<ld> vld; typedef vector<vld> vvld; typedef vector<vvld> vvvld; typedef vector<string> vst; typedef vector<vst> vvst; typedef pair<ld, ld> pld; typedef complex<double> base; #define inmin(a, b) a = min(a, (b)) #define inmax(a, b) a = max(a, (b)) #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define sqr(x) ((x) * (x)) #define fori(i, n) for (int i = 0; i < int(n); ++i) #define SZ(a) ((int)((a).size())) #define triple(T) tuple<T, T, T> #define quad(T) tuple<T, T, T, T> #define watch(x) cerr << (#x) << " = " << (x) << endl; const double PI = 2 * acos(0.0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; template <class T0, class T1> inline ostream &operator<<(ostream &out, pair<T0, T1> &a) { return out << "{" << a.first << ", " << a.second << "}"; } template <class T0, class T1, class T2> inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) { return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}"; } template <class T0, class T1, class T2, class T3> inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) { return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " << get<3>(a) << "}"; } template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) { out << "["; fori(i, a.size()) out << a[i] << vector<string>{", ", "] "}[i + 1 == a.size()]; return out; } void smain(); signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef RUS_HOME freopen("input.txt", "r", stdin); clock_t start = clock(); #endif // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cout << setprecision(12) << fixed; smain(); #ifdef RUS_HOME cout << "\n\nTOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl; #endif } const int oo = 1e9; const int N = 1e5 + 100; int MOD = 1e9 + 7; vi gx[N], gy[N]; vi cur(N); vi p[N]; void uni(int a, int b) { a = cur[a]; b = cur[b]; if (p[a].size() > p[b].size()) swap(a, b); for (int i = 0; i < p[a].size(); i++) { p[b].push_back(p[a][i]); cur[p[a][i]] = b; } p[a].clear(); } void smain() { int n; cin >> n; vi x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; gx[x[i]].push_back(i); gy[y[i]].push_back(i); cur[i] = i; p[i].push_back(i); } for (int i = 0; i < N; i++) { for (int j = 1; j < gx[i].size(); j++) { uni(gx[i][j], gx[i][j - 1]); } for (int j = 1; j < gy[i].size(); j++) { uni(gy[i][j], gy[i][j - 1]); } } int ans = 0; for (int i = 0; i < N; i++) { set<int> sx, sy; for (int j = 0; j < p[i].size(); j++) { sx.insert(x[p[i][j]]); sy.insert(y[p[i][j]]); } ans += sx.size() * sy.size(); } cout << ans - n; }
#include <bits/stdc++.h> #include <random> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; #define int ll // #define int __int128 // #define ll __int128 typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<short> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<ld> vld; typedef vector<vld> vvld; typedef vector<vvld> vvvld; typedef vector<string> vst; typedef vector<vst> vvst; typedef pair<ld, ld> pld; typedef complex<double> base; #define inmin(a, b) a = min(a, (b)) #define inmax(a, b) a = max(a, (b)) #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define sqr(x) ((x) * (x)) #define fori(i, n) for (int i = 0; i < int(n); ++i) #define SZ(a) ((int)((a).size())) #define triple(T) tuple<T, T, T> #define quad(T) tuple<T, T, T, T> #define watch(x) cerr << (#x) << " = " << (x) << endl; const double PI = 2 * acos(0.0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; template <class T0, class T1> inline ostream &operator<<(ostream &out, pair<T0, T1> &a) { return out << "{" << a.first << ", " << a.second << "}"; } template <class T0, class T1, class T2> inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) { return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}"; } template <class T0, class T1, class T2, class T3> inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) { return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " << get<3>(a) << "}"; } template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) { out << "["; fori(i, a.size()) out << a[i] << vector<string>{", ", "] "}[i + 1 == a.size()]; return out; } void smain(); signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef RUS_HOME freopen("input.txt", "r", stdin); clock_t start = clock(); #endif // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cout << setprecision(12) << fixed; smain(); #ifdef RUS_HOME cout << "\n\nTOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl; #endif } const int oo = 1e9; const int N = 1e5 + 100; int MOD = 1e9 + 7; vi gx[N], gy[N]; vi cur(N); vi p[N]; void uni(int a, int b) { a = cur[a]; b = cur[b]; if (a == b) return; if (p[a].size() > p[b].size()) swap(a, b); for (int i = 0; i < p[a].size(); i++) { p[b].push_back(p[a][i]); cur[p[a][i]] = b; } p[a].clear(); } void smain() { int n; cin >> n; vi x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; gx[x[i]].push_back(i); gy[y[i]].push_back(i); cur[i] = i; p[i].push_back(i); } for (int i = 0; i < N; i++) { for (int j = 1; j < gx[i].size(); j++) { uni(gx[i][j], gx[i][j - 1]); } for (int j = 1; j < gy[i].size(); j++) { uni(gy[i][j], gy[i][j - 1]); } } int ans = 0; for (int i = 0; i < N; i++) { set<int> sx, sy; for (int j = 0; j < p[i].size(); j++) { sx.insert(x[p[i][j]]); sy.insert(y[p[i][j]]); } ans += sx.size() * sy.size(); } cout << ans - n; }
insert
103
103
103
105
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int ll #define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i) #define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i) using ll = long long; using vi = vector<int>; // rank無しなのでlog n class UnionFind { public: vi data; UnionFind(int size) { data.resize(size, -1); // rep(i, size) data[i] = -1; } bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool find(int x, int y) { return root(x) == root(y); } int root(int x) { // どの集合か return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; signed main() { int n; cin >> n; vector<int> x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; #define MAX 10005 UnionFind ufx(MAX), ufy(MAX); vector<vector<int>> sx(MAX), sy(MAX); rep(i, n) { sx[x[i]].push_back(y[i]); sy[y[i]].push_back(x[i]); } rep(i, MAX) { FOR(j, 1, sx[i].size()) ufy.unite(sx[i][0], sx[i][j]); FOR(j, 1, sy[i].size()) ufx.unite(sy[i][0], sy[i][j]); } vector<int> usedx(MAX); int maxv = 0; rep(i, n) if (usedx[ufx.root(x[i])] == 0) { maxv += ufx.size(x[i]) * ufy.size(y[i]); usedx[ufx.root(x[i])] = 1; } cout << maxv - n << endl; }
#include <bits/stdc++.h> using namespace std; #define int ll #define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i) #define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i) using ll = long long; using vi = vector<int>; // rank無しなのでlog n class UnionFind { public: vi data; UnionFind(int size) { data.resize(size, -1); // rep(i, size) data[i] = -1; } bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool find(int x, int y) { return root(x) == root(y); } int root(int x) { // どの集合か return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; signed main() { int n; cin >> n; vector<int> x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; #define MAX 100005 UnionFind ufx(MAX), ufy(MAX); vector<vector<int>> sx(MAX), sy(MAX); rep(i, n) { sx[x[i]].push_back(y[i]); sy[y[i]].push_back(x[i]); } rep(i, MAX) { FOR(j, 1, sx[i].size()) ufy.unite(sx[i][0], sx[i][j]); FOR(j, 1, sy[i].size()) ufx.unite(sy[i][0], sy[i][j]); } vector<int> usedx(MAX); int maxv = 0; rep(i, n) if (usedx[ufx.root(x[i])] == 0) { maxv += ufx.size(x[i]) * ufy.size(y[i]); usedx[ufx.root(x[i])] = 1; } cout << maxv - n << endl; }
replace
46
47
46
47
0
p02998
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; class UnionFind { public: // parent node index if not root index // minus size of the tree if root index std::vector<int> data; UnionFind(int n) { data.resize(n, -1); } int find(int x) { if (data[x] < 0) { return x; } else { int r = find(data[x]); data[x] = r; return r; } } void unite(int x, int y) { int r = find(x); int s = find(y); if (r != s) { data[r] += data[s]; data[s] = r; } } int count(int x) { return -data[find(x)]; } }; template <typename T> int compress(vector<T> &x) { int n = x.size(); vector<T> xs(n); for (int i = 0; i < n; i++) xs[i] = x[i]; sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); for (int i = 0; i < n; i++) { x[i] = find(xs.begin(), xs.end(), x[i]) - xs.begin(); } return xs.size(); } int main() { int N; cin >> N; vector<int> X(N), Y(N); for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; X[i]--, Y[i]--; } compress(X); compress(Y); UnionFind uf(2 * N); for (int i = 0; i < N; i++) { uf.unite(X[i], Y[i] + N); } map<int, int> nx, ny; for (int i = 0; i < 2 * N; i++) { int r = uf.find(i); int c = uf.count(r); if (c <= 1) continue; if (i < N) { nx[r]++; } else { ny[r]++; } } ll dots = 0; for (auto q : nx) { dots += (ll)q.second * ny[q.first]; } ll ans = dots - N; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; class UnionFind { public: // parent node index if not root index // minus size of the tree if root index std::vector<int> data; UnionFind(int n) { data.resize(n, -1); } int find(int x) { if (data[x] < 0) { return x; } else { int r = find(data[x]); data[x] = r; return r; } } void unite(int x, int y) { int r = find(x); int s = find(y); if (r != s) { data[r] += data[s]; data[s] = r; } } int count(int x) { return -data[find(x)]; } }; template <typename T> int compress(vector<T> &x) { int n = x.size(); vector<T> xs(n); for (int i = 0; i < n; i++) xs[i] = x[i]; sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); for (int i = 0; i < n; i++) { x[i] = lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin(); } return xs.size(); } int main() { int N; cin >> N; vector<int> X(N), Y(N); for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; X[i]--, Y[i]--; } compress(X); compress(Y); UnionFind uf(2 * N); for (int i = 0; i < N; i++) { uf.unite(X[i], Y[i] + N); } map<int, int> nx, ny; for (int i = 0; i < 2 * N; i++) { int r = uf.find(i); int c = uf.count(r); if (c <= 1) continue; if (i < N) { nx[r]++; } else { ny[r]++; } } ll dots = 0; for (auto q : nx) { dots += (ll)q.second * ny[q.first]; } ll ans = dots - N; cout << ans << '\n'; return 0; }
replace
42
43
42
43
TLE
p02998
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n; i >= 0; i--) #define REP(i, s, t) for (int i = s; i <= t; i++) #define RREP(i, s, t) for (int i = s; i >= t; i--) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 #define int long long typedef pair<int, int> P; int x[100010], y[100010]; vector<int> X[100010], Y[100010]; bool visited[100010]; map<P, int> mp; int ans = 0; set<int> stX, stY; set<P> st; int cnt = 0; void search(int x, int y) { if (cnt >= 2000000) return; if (visited[mp[{x, y}]]) return; stX.insert(x); stY.insert(y); st.insert({x, y}); visited[mp[{x, y}]] = true; for (auto to : X[y]) { search(to, y); } for (auto to : Y[x]) { search(x, to); } } signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; rep(i, N) { cin >> x[i] >> y[i]; X[y[i]].push_back(x[i]); Y[x[i]].push_back(y[i]); mp[{x[i], y[i]}] = i; } int ans = 0; rep(i, N) { if (cnt >= 2000000) { cout << 0 << endl; return 0; } if (visited[i]) continue; search(x[i], y[i]); ans += stX.size() * stY.size() - st.size(); st.clear(); stX.clear(); stY.clear(); } cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n; i >= 0; i--) #define REP(i, s, t) for (int i = s; i <= t; i++) #define RREP(i, s, t) for (int i = s; i >= t; i--) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 #define int long long typedef pair<int, int> P; int x[100010], y[100010]; vector<int> X[100010], Y[100010]; bool visited[100010]; map<P, int> mp; int ans = 0; set<int> stX, stY; set<P> st; int cnt = 0; void search(int x, int y) { if (cnt >= 2000000) return; cnt++; if (visited[mp[{x, y}]]) return; stX.insert(x); stY.insert(y); st.insert({x, y}); visited[mp[{x, y}]] = true; for (auto to : X[y]) { search(to, y); } for (auto to : Y[x]) { search(x, to); } } signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; rep(i, N) { cin >> x[i] >> y[i]; X[y[i]].push_back(x[i]); Y[x[i]].push_back(y[i]); mp[{x[i], y[i]}] = i; } int ans = 0; rep(i, N) { if (cnt >= 2000000) { cout << 0 << endl; return 0; } if (visited[i]) continue; search(x[i], y[i]); ans += stX.size() * stY.size() - st.size(); st.clear(); stX.clear(); stY.clear(); } cout << ans << endl; return 0; }
insert
25
25
25
26
TLE
p02998
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; (i) < (int)(n); (i)++) using namespace std; int main() { int n; scanf("%d", &n); int N = 101; vector<vector<int>> g(2 * N); rep(i, n) { int x, y; scanf("%d%d", &x, &y); x--, y--; g[x].push_back(y + N); g[y + N].push_back(x); } vector<bool> used(2 * N); int x = 0, y = 0; function<void(int)> dfs = [&](int u) { if (u < N) x++; else y++; used[u] = true; for (auto v : g[u]) if (!used[v]) { dfs(v); } }; long long ans = -n; rep(i, 2 * N) { if (!used[i]) { x = 0, y = 0; dfs(i); ans += (long long)x * y; } } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; (i) < (int)(n); (i)++) using namespace std; int main() { int n; scanf("%d", &n); int N = 101010; vector<vector<int>> g(2 * N); rep(i, n) { int x, y; scanf("%d%d", &x, &y); x--, y--; g[x].push_back(y + N); g[y + N].push_back(x); } vector<bool> used(2 * N); int x = 0, y = 0; function<void(int)> dfs = [&](int u) { if (u < N) x++; else y++; used[u] = true; for (auto v : g[u]) if (!used[v]) { dfs(v); } }; long long ans = -n; rep(i, 2 * N) { if (!used[i]) { x = 0, y = 0; dfs(i); ans += (long long)x * y; } } printf("%lld\n", ans); return 0; }
replace
7
8
7
8
0
p02998
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; const int V = 10005; vector<int> to[V * 2]; vector<int> cnt; vector<int> visited(V * 2); void dfs(int v) { if (visited[v]) return; visited[v] = true; cnt[v / V]++; for (auto u : to[v]) dfs(u); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; y += V; to[x].push_back(y); to[y].push_back(x); } long long ans = 0; for (int i = 0; i < V * 2; i++) { if (visited[i]) continue; cnt = vector<int>(2, 0); dfs(i); ans += (long long)cnt[0] * cnt[1]; } ans -= n; cout << ans << endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; const int V = 100005; vector<int> to[V * 2]; vector<int> cnt; vector<int> visited(V * 2); void dfs(int v) { if (visited[v]) return; visited[v] = true; cnt[v / V]++; for (auto u : to[v]) dfs(u); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; y += V; to[x].push_back(y); to[y].push_back(x); } long long ans = 0; for (int i = 0; i < V * 2; i++) { if (visited[i]) continue; cnt = vector<int>(2, 0); dfs(i); ans += (long long)cnt[0] * cnt[1]; } ans -= n; cout << ans << endl; }
replace
9
10
9
10
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int64_t>>; static const int64_t MAX = 10; static vector<bool> seen(MAX * 2, false); pair<int64_t, int64_t> dfs(const Graph &g, int64_t v, bool isX = true) { if (seen[v]) return {0, 0}; seen[v] = true; pair<int64_t, int64_t> num = {0, 0}; if (isX) num.first++; else num.second++; for (int64_t next_v : g[v]) { pair<int64_t, int64_t> child = dfs(g, next_v, !isX); num.first += child.first; num.second += child.second; } return num; } int main() { int64_t n; cin >> n; Graph g(MAX * 2); for (int64_t i = 0; i < n; i++) { int64_t x, y; cin >> x >> y; x--; y--; g[x].push_back(y + MAX); g[y + MAX].push_back(x); } int64_t ans = 0; for (int64_t i = 0; i < MAX; i++) { pair<int64_t, int64_t> num = dfs(g, i); ans += num.first * num.second; } ans -= n; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int64_t>>; static const int64_t MAX = 1e5; static vector<bool> seen(MAX * 2, false); pair<int64_t, int64_t> dfs(const Graph &g, int64_t v, bool isX = true) { if (seen[v]) return {0, 0}; seen[v] = true; pair<int64_t, int64_t> num = {0, 0}; if (isX) num.first++; else num.second++; for (int64_t next_v : g[v]) { pair<int64_t, int64_t> child = dfs(g, next_v, !isX); num.first += child.first; num.second += child.second; } return num; } int main() { int64_t n; cin >> n; Graph g(MAX * 2); for (int64_t i = 0; i < n; i++) { int64_t x, y; cin >> x >> y; x--; y--; g[x].push_back(y + MAX); g[y + MAX].push_back(x); } int64_t ans = 0; for (int64_t i = 0; i < MAX; i++) { pair<int64_t, int64_t> num = dfs(g, i); ans += num.first * num.second; } ans -= n; cout << ans << endl; return 0; }
replace
4
5
4
5
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vt = vector<T>; template <class T> using vvt = vector<vt<T>>; template <class T> using ttt = tuple<T, T>; using tii = tuple<int, int>; using vi = vector<int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define mt make_tuple #define ALL(a) (a).begin(), (a).end() #define FST first #define SEC second #define DEB cerr << "!" << endl #define SHOW(a, b) cerr << (a) << " " << (b) << endl #define DIV int(1e9 + 7) const int INF = (INT_MAX / 2); const ll LLINF = (LLONG_MAX / 2); const double eps = 1e-8; // const double PI = M_PI; inline ll pow(ll x, ll n, ll m) { ll r = 1; while (n > 0) { if ((n & 1) == 1) r = r * x % m; x = x * x % m; n >>= 1; } return r % m; } inline ll lcm(ll d1, ll d2) { return d1 / __gcd(d1, d2) * d2; } #define chmax(a, b) a = max(a, b) class UF { public: vi value; vi over; // When over < 0, 'over' keep number of node(using negative number). // -1 means this tree is a node. int root(int index) { int t = index; stack<int> stack_i; while (over[t] >= 0) { stack_i.push(t); t = over[t]; } while (!stack_i.empty()) { int i = stack_i.top(); stack_i.pop(); over[i] = t; } // reconnect return t; } void merge(int a, int b) { if (this->root(a) == this->root(b)) return; over[root(a)] += over[root(b)]; // over have a number of nodes. over[root(b)] = root(a); } int NumNode(int a) { return -over[root(a)]; } UF(int Nodes) { value.resize(Nodes); over.resize(Nodes); rep(i, Nodes) over[i] = -1; } }; /*Coding Space*/ UF uf(300050); int cnt[200020][2] = {}; const int D = 100005; int main() { int n; cin >> n; rep(i, n) { int x, y; cin >> x >> y; y += D; uf.merge(x, y); } rep(i, 200020) { cnt[uf.root(i)][i / D]++; } ll ans = 0; rep(i, 200020) ans += cnt[i][0] * cnt[i][1]; cout << ans - n << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vt = vector<T>; template <class T> using vvt = vector<vt<T>>; template <class T> using ttt = tuple<T, T>; using tii = tuple<int, int>; using vi = vector<int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define mt make_tuple #define ALL(a) (a).begin(), (a).end() #define FST first #define SEC second #define DEB cerr << "!" << endl #define SHOW(a, b) cerr << (a) << " " << (b) << endl #define DIV int(1e9 + 7) const int INF = (INT_MAX / 2); const ll LLINF = (LLONG_MAX / 2); const double eps = 1e-8; // const double PI = M_PI; inline ll pow(ll x, ll n, ll m) { ll r = 1; while (n > 0) { if ((n & 1) == 1) r = r * x % m; x = x * x % m; n >>= 1; } return r % m; } inline ll lcm(ll d1, ll d2) { return d1 / __gcd(d1, d2) * d2; } #define chmax(a, b) a = max(a, b) class UF { public: vi value; vi over; // When over < 0, 'over' keep number of node(using negative number). // -1 means this tree is a node. int root(int index) { int t = index; stack<int> stack_i; while (over[t] >= 0) { stack_i.push(t); t = over[t]; } while (!stack_i.empty()) { int i = stack_i.top(); stack_i.pop(); over[i] = t; } // reconnect return t; } void merge(int a, int b) { if (this->root(a) == this->root(b)) return; over[root(a)] += over[root(b)]; // over have a number of nodes. over[root(b)] = root(a); } int NumNode(int a) { return -over[root(a)]; } UF(int Nodes) { value.resize(Nodes); over.resize(Nodes); rep(i, Nodes) over[i] = -1; } }; /*Coding Space*/ UF uf(300050); ll cnt[400020][2] = {}; const int D = 100005; int main() { int n; cin >> n; rep(i, n) { int x, y; cin >> x >> y; y += D; uf.merge(x, y); } rep(i, 200020) { cnt[uf.root(i)][i / D]++; } ll ans = 0; rep(i, 200020) ans += cnt[i][0] * cnt[i][1]; cout << ans - n << endl; }
replace
67
68
67
68
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MAXNUM 111 #define rep(i, s, t) for (int i = s; i < t; i++) #define pii pair<int, int> typedef long long ll; pii num[MAXNUM]; int dset[MAXNUM * 2], allx[MAXNUM], ally[MAXNUM], xsize, ysize; int ssizex[MAXNUM * 2], ssizey[MAXNUM * 2]; int fa(int a) { if (dset[a] != a) return dset[a] = fa(dset[a]); return a; } int main() { int n, a, b; scanf("%d", &n); rep(i, 1, n + 1) scanf("%d%d", &a, &b), num[i] = {a, b}, allx[++xsize] = a, ally[++ysize] = b; sort(allx + 1, allx + xsize + 1), sort(ally + 1, ally + ysize + 1); xsize = unique(allx + 1, allx + xsize + 1) - allx - 1, ysize = unique(ally + 1, ally + ysize + 1) - ally - 1; rep(i, 1, xsize + ysize + 1) dset[i] = i; rep(i, 1, n + 1) { int k1 = lower_bound(allx + 1, allx + xsize + 1, num[i].first) - allx, k2 = lower_bound(ally + 1, ally + ysize + 1, num[i].second) - ally; dset[fa(k1)] = fa(k2 + xsize); } rep(i, 1, xsize + 1) ssizex[fa(i)]++; rep(i, 1, ysize + 1) ssizey[fa(i + xsize)]++; ll res = 0; rep(i, 1, xsize + ysize + 1) if (fa(i) == i) res += ssizex[i] * 1ll * ssizey[i]; printf("%lld\n", res - n); }
#include <bits/stdc++.h> using namespace std; #define MAXNUM 111111 #define rep(i, s, t) for (int i = s; i < t; i++) #define pii pair<int, int> typedef long long ll; pii num[MAXNUM]; int dset[MAXNUM * 2], allx[MAXNUM], ally[MAXNUM], xsize, ysize; int ssizex[MAXNUM * 2], ssizey[MAXNUM * 2]; int fa(int a) { if (dset[a] != a) return dset[a] = fa(dset[a]); return a; } int main() { int n, a, b; scanf("%d", &n); rep(i, 1, n + 1) scanf("%d%d", &a, &b), num[i] = {a, b}, allx[++xsize] = a, ally[++ysize] = b; sort(allx + 1, allx + xsize + 1), sort(ally + 1, ally + ysize + 1); xsize = unique(allx + 1, allx + xsize + 1) - allx - 1, ysize = unique(ally + 1, ally + ysize + 1) - ally - 1; rep(i, 1, xsize + ysize + 1) dset[i] = i; rep(i, 1, n + 1) { int k1 = lower_bound(allx + 1, allx + xsize + 1, num[i].first) - allx, k2 = lower_bound(ally + 1, ally + ysize + 1, num[i].second) - ally; dset[fa(k1)] = fa(k2 + xsize); } rep(i, 1, xsize + 1) ssizex[fa(i)]++; rep(i, 1, ysize + 1) ssizey[fa(i + xsize)]++; ll res = 0; rep(i, 1, xsize + ysize + 1) if (fa(i) == i) res += ssizex[i] * 1ll * ssizey[i]; printf("%lld\n", res - n); }
replace
2
3
2
3
0
p02998
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 n, offset = 100010; vector<vector<int>> g(300010); vector<bool> used(300010, false); vector<ll> cnt(2); void dfs(int v) { if (used[v]) return; used[v] = true; if (v >= offset) cnt[1]++; else cnt[0]++; for (auto itr : g[v]) { dfs(itr); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; vector<int> ten; rep(i, n) { int x, y; cin >> x >> y; y += offset; ten.push_back(x); ten.push_back(y); g[x].push_back(y); g[y].push_back(x); } ll ans = 0; for (auto itr : ten) { if (used[ten[itr]]) continue; rep(j, 2) cnt[j] = 0; dfs(itr); ans += cnt[0] * cnt[1]; } ans -= n; cout << ans << endl; }
#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 n, offset = 100010; vector<vector<int>> g(300010); vector<bool> used(300010, false); vector<ll> cnt(2); void dfs(int v) { if (used[v]) return; used[v] = true; if (v >= offset) cnt[1]++; else cnt[0]++; for (auto itr : g[v]) { dfs(itr); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; vector<int> ten; rep(i, n) { int x, y; cin >> x >> y; y += offset; ten.push_back(x); ten.push_back(y); g[x].push_back(y); g[y].push_back(x); } ll ans = 0; for (auto itr : ten) { if (used[itr]) continue; rep(j, 2) cnt[j] = 0; dfs(itr); ans += cnt[0] * cnt[1]; } ans -= n; cout << ans << endl; }
replace
109
110
109
110
-11
p02998
C++
Runtime Error
// Author: πα #include <bits/stdc++.h> using namespace std; #define long int64_t const int N = 1e5 + 5; vector<int> g[N]; bool vis[N]; int cl, cr, ce; void dfs(int u) { if (vis[u]) return; vis[u] = 1; if (u < N) cl++, ce += g[u].size(); else cr++; for (auto v : g[u]) dfs(v); } int main() { int n, u, v, i; long ans = 0; cin >> n; for (i = 0; i < n; ++i) { cin >> u >> v; v += N; g[u].push_back(v); g[v].push_back(u); } for (i = 1; i < N; ++i) if (not vis[i]) { cl = cr = ce = 0; dfs(i); ans += 1LL * cl * cr - ce; } cout << ans; return 0; }
// Author: πα #include <bits/stdc++.h> using namespace std; #define long int64_t const int N = 1e5 + 5; vector<int> g[N + N]; bool vis[N + N]; int cl, cr, ce; void dfs(int u) { if (vis[u]) return; vis[u] = 1; if (u < N) cl++, ce += g[u].size(); else cr++; for (auto v : g[u]) dfs(v); } int main() { int n, u, v, i; long ans = 0; cin >> n; for (i = 0; i < n; ++i) { cin >> u >> v; v += N; g[u].push_back(v); g[v].push_back(u); } for (i = 1; i < N; ++i) if (not vis[i]) { cl = cr = ce = 0; dfs(i); ans += 1LL * cl * cr - ce; } cout << ans; return 0; }
replace
7
9
7
9
0
p02998
C++
Runtime Error
// template version 1.12 using namespace std; #include <bits/stdc++.h> #include <iostream> // varibable settings #define infile "../test/sample-1.in" #define int long long //{{{ const int INF = 1e18; const int MOD = 1e9 + 7; //}}} // define basic macro {{{ #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define _rrep(i, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define uni(x) \ sort(all(x)); \ x.erase(unique(all(x)), x.end()) #define ub upper_bound #define lb lower_bound #define posl(A, x) (lower_bound(all(A), x) - A.begin()) #define posu(A, x) (upper_bound(all(A), x) - A.begin()) template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); } template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); } typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef long double ld; typedef pair<int, int> pii; typedef tuple<int, int, int> iii; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; #if defined(PCM) || defined(LOCAL) #include "lib/dump.hpp" #else #define dump(...) 42 #define dump_1d(...) 42 #define dump_2d(...) 42 #endif //}}} struct UnionFind { /*{{{*/ vector<int> data; // size defined only for root node int count; UnionFind(int size) : data(size, -1), count(size) {} bool merge(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; count--; } return x != y; } int root(int x) { return (data[x] < 0 ? x : data[x] = root(data[x])); } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -data[root(x)]; } }; /*}}}*/ #define MAXN 30 struct kousi { int x, y, cnt; }; int solve() { int n; cin >> n; vi x(n), y(n); UnionFind uf(200001); vvi Y(MAXN + 1, vi()); vvi X(MAXN + 1, vi()); rep(i, n) { cin >> x[i] >> y[i]; uf.merge(x[i], y[i] + MAXN); Y[y[i]].pb(x[i]); X[x[i]].pb(y[i]); } each(el, Y) { rep(i, 1, sz(el)) { uf.merge(el[i - 1], el[i]); } } each(el, X) { rep(i, 1, sz(el)) { uf.merge(el[i - 1] + MAXN, el[i] + MAXN); } } map<int, kousi> roots; rep(i, 1, MAXN + 1) { roots[uf.root(i)].x += 1; } rep(i, 1, MAXN + 1) { roots[uf.root(i + MAXN)].y += 1; } rep(i, n) { roots[uf.root(x[i])].cnt++; } int res = 0; each(root, roots) { kousi k = root.second; // dump(p, k.x, k.y, k.cnt); res += k.x * k.y - k.cnt; } cout << res << endl; return 0; } signed main() { //{{{ #ifdef INPUT_FROM_FILE std::ifstream in(infile); std::cin.rdbuf(in.rdbuf()); #endif solve(); return 0; } //}}}
// template version 1.12 using namespace std; #include <bits/stdc++.h> #include <iostream> // varibable settings #define infile "../test/sample-1.in" #define int long long //{{{ const int INF = 1e18; const int MOD = 1e9 + 7; //}}} // define basic macro {{{ #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define _rrep(i, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define uni(x) \ sort(all(x)); \ x.erase(unique(all(x)), x.end()) #define ub upper_bound #define lb lower_bound #define posl(A, x) (lower_bound(all(A), x) - A.begin()) #define posu(A, x) (upper_bound(all(A), x) - A.begin()) template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); } template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); } typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef long double ld; typedef pair<int, int> pii; typedef tuple<int, int, int> iii; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; #if defined(PCM) || defined(LOCAL) #include "lib/dump.hpp" #else #define dump(...) 42 #define dump_1d(...) 42 #define dump_2d(...) 42 #endif //}}} struct UnionFind { /*{{{*/ vector<int> data; // size defined only for root node int count; UnionFind(int size) : data(size, -1), count(size) {} bool merge(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; count--; } return x != y; } int root(int x) { return (data[x] < 0 ? x : data[x] = root(data[x])); } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -data[root(x)]; } }; /*}}}*/ #define MAXN 100000 struct kousi { int x, y, cnt; }; int solve() { int n; cin >> n; vi x(n), y(n); UnionFind uf(200001); vvi Y(MAXN + 1, vi()); vvi X(MAXN + 1, vi()); rep(i, n) { cin >> x[i] >> y[i]; uf.merge(x[i], y[i] + MAXN); Y[y[i]].pb(x[i]); X[x[i]].pb(y[i]); } each(el, Y) { rep(i, 1, sz(el)) { uf.merge(el[i - 1], el[i]); } } each(el, X) { rep(i, 1, sz(el)) { uf.merge(el[i - 1] + MAXN, el[i] + MAXN); } } map<int, kousi> roots; rep(i, 1, MAXN + 1) { roots[uf.root(i)].x += 1; } rep(i, 1, MAXN + 1) { roots[uf.root(i + MAXN)].y += 1; } rep(i, n) { roots[uf.root(x[i])].cnt++; } int res = 0; each(root, roots) { kousi k = root.second; // dump(p, k.x, k.y, k.cnt); res += k.x * k.y - k.cnt; } cout << res << endl; return 0; } signed main() { //{{{ #ifdef INPUT_FROM_FILE std::ifstream in(infile); std::cin.rdbuf(in.rdbuf()); #endif solve(); return 0; } //}}}
replace
87
88
87
88
0
p02998
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <set> #include <stdlib.h> #include <string> #include <utility> #include <vector> #define llint long long using namespace std; typedef pair<llint, llint> P; struct UnionFind { int size; vector<int> parent; UnionFind() {} UnionFind(int size) { this->size = size; parent.resize(size + 1); init(); } void init() { for (int i = 0; i <= size; i++) parent[i] = i; } int root(int i) { if (parent[i] == i) return i; return parent[i] = root(parent[i]); } bool same(int i, int j) { return root(i) == root(j); } void unite(int i, int j) { int root_i = root(i), root_j = root(j); if (root_i == root_j) return; parent[root_i] = root_j; } }; llint n; llint x[100005], y[100005]; UnionFind uf(100005); vector<llint> vec[100005], vecx[100005]; set<llint> S[100005]; llint cnt[100005]; int main(void) { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; for (int i = 1; i <= n; i++) vec[x[i]].push_back(y[i]); for (int i = 1; i <= n; i++) vecx[y[i]].push_back(x[i]); for (int i = 1; i < 100005; i++) { for (int j = 1; j < vec[i].size(); j++) uf.unite(vec[i][j - 1], vec[i][j]); } for (int i = 1; i < 100005; i++) { for (int j = 0; j < vec[i].size(); j++) { S[uf.root(i)].insert(vecx[i][j]); } cnt[uf.root(i)]++; } llint ans = 0; for (int i = 1; i < 100005; i++) { ans += S[i].size() * cnt[i]; } ans -= n; cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <set> #include <stdlib.h> #include <string> #include <utility> #include <vector> #define llint long long using namespace std; typedef pair<llint, llint> P; struct UnionFind { int size; vector<int> parent; UnionFind() {} UnionFind(int size) { this->size = size; parent.resize(size + 1); init(); } void init() { for (int i = 0; i <= size; i++) parent[i] = i; } int root(int i) { if (parent[i] == i) return i; return parent[i] = root(parent[i]); } bool same(int i, int j) { return root(i) == root(j); } void unite(int i, int j) { int root_i = root(i), root_j = root(j); if (root_i == root_j) return; parent[root_i] = root_j; } }; llint n; llint x[100005], y[100005]; UnionFind uf(100005); vector<llint> vec[100005], vecx[100005]; set<llint> S[100005]; llint cnt[100005]; int main(void) { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; for (int i = 1; i <= n; i++) vec[x[i]].push_back(y[i]); for (int i = 1; i <= n; i++) vecx[y[i]].push_back(x[i]); for (int i = 1; i < 100005; i++) { for (int j = 1; j < vec[i].size(); j++) uf.unite(vec[i][j - 1], vec[i][j]); } for (int i = 1; i < 100005; i++) { for (int j = 0; j < vecx[i].size(); j++) { S[uf.root(i)].insert(vecx[i][j]); } cnt[uf.root(i)]++; } llint ans = 0; for (int i = 1; i < 100005; i++) { ans += S[i].size() * cnt[i]; } ans -= n; cout << ans << endl; return 0; }
replace
63
64
63
64
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mem(arr, i) fill(arr, arr + sizeof(arr), i) #define MEM(arr, i) memset(arr, i, sizeof(arr)) #define Push push_back #define Pair make_pair #define ALL(x) (x).begin(), (x).end() #define X first #define Y second #define ACCEL \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) typedef unsigned long long ull; typedef long long lli; typedef pair<int, int> pii; typedef pair<lli, lli> pll; typedef pair<pll, lli> p3l; typedef vector<int> vcI; typedef vector<lli> vcL; typedef vector<pii> vPI; typedef vector<pll> vPL; typedef vector<p3l> v3L; typedef vector<vcL> vvL; // typedef priority_queue<T> prior_S<T>; // typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>; const double PI = 3.141592653589793; const lli I_MAX = 1LL << 60; lli mod = 1000000007; /// templates /// const lli maxN = 2E5; vcL inv(maxN + 5, 1); vcL fac(maxN + 5, 1); void ADD(lli &x, lli y) { x += y; if (x >= mod) x -= mod; if (x < 0) x += mod; } void MUL(lli &x, lli y) { x *= y; x = (x % mod + mod) % mod; } lli mypow(lli b, lli e) { lli ans = 1; while (e) { if (e & 1) MUL(ans, b); MUL(b, b); e >>= 1; } return ans; } lli modinv(lli n) { return mypow(n, mod - 2); } void calcInv(lli n) { for (int i = 2; i <= n; ++i) { inv[i] = (mod - mod / i) * inv[mod % i] % mod; } } void calcFac(lli n) { for (int i = 2; i <= n; ++i) { fac[i] = fac[i - 1] * i % mod; } } lli cm(lli a, lli b) { lli ans = 1; if (a < b) return 0; MUL(ans, inv[fac[a - b]]); MUL(ans, inv[fac[b]]); MUL(ans, fac[a]); return ans; } lli Lucas(lli n, lli m) { if (m == 0) return 1; return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod; } lli doLucas(lli n, lli m) { calcInv(mod); calcFac(mod); return Lucas(n, m); } /// coding area /// const lli maxn = 1E3; void precal() { return; } void solve() { lli n = 1, m, sum = 0, ans = 0, cnt = 0, cnt0 = 0, ext = 0; string s; cin >> n; v3L num(n); set<lli> row[maxn + 1]; set<lli> col[maxn + 1]; bool visX[maxn], visY[maxn]; MEM(visX, false); MEM(visY, false); for (auto &x : num) { cin >> x.X.X >> x.X.Y; x.Y = ++cnt; row[x.X.X - 1].insert(x.X.Y - 1); col[x.X.Y - 1].insert(x.X.X - 1); } queue<lli> nextX, nextY; lli nX = maxn, nY = maxn; lli flag = 0; while (cnt0 < n) { lli cntX = 1, cntY = 0; for (ext; ext < maxn; ++ext) { if (!visX[ext]) { visX[ext] = true; nX = ext; nY = maxn; break; } } if (ext == maxn) break; while (cnt0 < n) { for (auto y : row[nX]) { if (!visY[y]) { visY[y] = true; ++cnt0; ++cntY; nextY.push(y); } } for (auto x : col[nY]) { if (!visX[x]) { visX[x] = true; ++cnt0; ++cntX; nextX.push(x); } } if (!nextX.empty()) { nX = nextX.front(); nextX.pop(); ++flag; } else nX = maxn; if (!nextY.empty()) { nY = nextY.front(); nextY.pop(); ++flag; } else nY = maxn; if (flag == 0) break; else flag = 0; } ans += cntX * cntY; // cout << "ans += " << cntX << " * " << cntY << '\n'; } cout << ans - n << '\n'; } int main() { precal(); int t = 1; #ifdef LOCAL t = INT_MAX; #else ACCEL; #endif // cin >> t; for (int i = 1; i <= t; ++i) { // printf("Case #%d: ", i ); solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define mem(arr, i) fill(arr, arr + sizeof(arr), i) #define MEM(arr, i) memset(arr, i, sizeof(arr)) #define Push push_back #define Pair make_pair #define ALL(x) (x).begin(), (x).end() #define X first #define Y second #define ACCEL \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) typedef unsigned long long ull; typedef long long lli; typedef pair<int, int> pii; typedef pair<lli, lli> pll; typedef pair<pll, lli> p3l; typedef vector<int> vcI; typedef vector<lli> vcL; typedef vector<pii> vPI; typedef vector<pll> vPL; typedef vector<p3l> v3L; typedef vector<vcL> vvL; // typedef priority_queue<T> prior_S<T>; // typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>; const double PI = 3.141592653589793; const lli I_MAX = 1LL << 60; lli mod = 1000000007; /// templates /// const lli maxN = 2E5; vcL inv(maxN + 5, 1); vcL fac(maxN + 5, 1); void ADD(lli &x, lli y) { x += y; if (x >= mod) x -= mod; if (x < 0) x += mod; } void MUL(lli &x, lli y) { x *= y; x = (x % mod + mod) % mod; } lli mypow(lli b, lli e) { lli ans = 1; while (e) { if (e & 1) MUL(ans, b); MUL(b, b); e >>= 1; } return ans; } lli modinv(lli n) { return mypow(n, mod - 2); } void calcInv(lli n) { for (int i = 2; i <= n; ++i) { inv[i] = (mod - mod / i) * inv[mod % i] % mod; } } void calcFac(lli n) { for (int i = 2; i <= n; ++i) { fac[i] = fac[i - 1] * i % mod; } } lli cm(lli a, lli b) { lli ans = 1; if (a < b) return 0; MUL(ans, inv[fac[a - b]]); MUL(ans, inv[fac[b]]); MUL(ans, fac[a]); return ans; } lli Lucas(lli n, lli m) { if (m == 0) return 1; return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod; } lli doLucas(lli n, lli m) { calcInv(mod); calcFac(mod); return Lucas(n, m); } /// coding area /// const lli maxn = 1E5; void precal() { return; } void solve() { lli n = 1, m, sum = 0, ans = 0, cnt = 0, cnt0 = 0, ext = 0; string s; cin >> n; v3L num(n); set<lli> row[maxn + 1]; set<lli> col[maxn + 1]; bool visX[maxn], visY[maxn]; MEM(visX, false); MEM(visY, false); for (auto &x : num) { cin >> x.X.X >> x.X.Y; x.Y = ++cnt; row[x.X.X - 1].insert(x.X.Y - 1); col[x.X.Y - 1].insert(x.X.X - 1); } queue<lli> nextX, nextY; lli nX = maxn, nY = maxn; lli flag = 0; while (cnt0 < n) { lli cntX = 1, cntY = 0; for (ext; ext < maxn; ++ext) { if (!visX[ext]) { visX[ext] = true; nX = ext; nY = maxn; break; } } if (ext == maxn) break; while (cnt0 < n) { for (auto y : row[nX]) { if (!visY[y]) { visY[y] = true; ++cnt0; ++cntY; nextY.push(y); } } for (auto x : col[nY]) { if (!visX[x]) { visX[x] = true; ++cnt0; ++cntX; nextX.push(x); } } if (!nextX.empty()) { nX = nextX.front(); nextX.pop(); ++flag; } else nX = maxn; if (!nextY.empty()) { nY = nextY.front(); nextY.pop(); ++flag; } else nY = maxn; if (flag == 0) break; else flag = 0; } ans += cntX * cntY; // cout << "ans += " << cntX << " * " << cntY << '\n'; } cout << ans - n << '\n'; } int main() { precal(); int t = 1; #ifdef LOCAL t = INT_MAX; #else ACCEL; #endif // cin >> t; for (int i = 1; i <= t; ++i) { // printf("Case #%d: ", i ); solve(); } return 0; }
replace
102
103
102
103
0
p02998
C++
Runtime Error
#include <algorithm> #include <iostream> #include <utility> #include <vector> using namespace std; using ll = long long int; constexpr int MAX = 10005; int n; vector<vector<int>> to(MAX * 2); vector<bool> visited(MAX * 2, false); vector<ll> cnt(2, 0); ll ret = 0; void dfs(int v) { if (visited[v]) return; visited[v] = true; cnt[v / MAX]++; for (int i = 0; i < to[v].size(); i++) dfs(to[v][i]); return; } int main(void) { cin >> n; for (size_t i = 0; i < n; i++) { int ai, bi; cin >> ai >> bi; bi += MAX; to[ai].push_back(bi); to[bi].push_back(ai); } ll ret = 0; for (int i = 0; i < MAX * 2; i++) { if (visited[i]) continue; cnt = vector<ll>(2, 0); dfs(i); ret += ll(cnt[0] * cnt[1]); } ret -= n; cout << ret << endl; return 0; }
#include <algorithm> #include <iostream> #include <utility> #include <vector> using namespace std; using ll = long long int; constexpr int MAX = 100005; int n; vector<vector<int>> to(MAX * 2); vector<bool> visited(MAX * 2, false); vector<ll> cnt(2, 0); ll ret = 0; void dfs(int v) { if (visited[v]) return; visited[v] = true; cnt[v / MAX]++; for (int i = 0; i < to[v].size(); i++) dfs(to[v][i]); return; } int main(void) { cin >> n; for (size_t i = 0; i < n; i++) { int ai, bi; cin >> ai >> bi; bi += MAX; to[ai].push_back(bi); to[bi].push_back(ai); } ll ret = 0; for (int i = 0; i < MAX * 2; i++) { if (visited[i]) continue; cnt = vector<ll>(2, 0); dfs(i); ret += ll(cnt[0] * cnt[1]); } ret -= n; cout << ret << endl; return 0; }
replace
6
7
6
7
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, x, n) for (int i = x; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(X) (X).begin(), (X).end() #define X first #define Y second #define pb push_back #define eb emplace_back using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; 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; } template <class A, size_t N, class T> void Fill(A (&a)[N], const T &v) { fill((T *)a, (T *)(a + N), v); } template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "{"; rep(i, t.size()) { os << t[i] << ","; } os << "}"; return os; } template <class T, size_t n> ostream &operator<<(ostream &os, const array<T, n> &t) { os << "{"; rep(i, n) { os << t[i] << ","; } os << "}"; return os; } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) { return os << "(" << t.first << "," << t.second << ")"; } const ll INF = 1e9 + 7; struct UnionFind { std::vector<int> data; // dataの各要素について // 負の値:その集合のルートであること示す。また、その絶対値は集合の要素数となっている。 // 正の値:親ノードの番号(dataのインデックス)。root()を呼び出すたびに集合のルートを指すように書きなおされるので木はそんなに深くならない // 初期化 size:最大要素数 UnionFind(int size) : data(size, -1) {} // 集合を併合する // すでに同じ集合だった場合は、falseが返る bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { // 要素数の大きな方へ合併するためのswap if (data[y] < data[x]) std::swap(x, y); // 要素数を加算する data[x] += data[y]; // yの属する集合のルートをxに変更 data[y] = x; } return x != y; } // 同じ集合かどうか判定 bool find(int x, int y) { return root(x) == root(y); } // 集合の識別番号を返す int root(int x) { // 負の値を持つものがその集合のルート // 正の値は同じ集合に属するものを指す(辿ればいずれルートへ着く) return (data[x] < 0) ? x : data[x] = root(data[x]); } // 集合の要素数を返す int size(int x) { return -data[root(x)]; } }; int main() { ios_base::sync_with_stdio(false); ll N, ans = 0; map<int, vector<int>> mp; cin >> N; rep(i, N) { int x, y; cin >> x >> y; mp[x].push_back(y); } UnionFind uf(N); for (auto p : mp) { auto ys = p.Y; for (int y : ys) uf.unite(ys[0], y); } for (auto p : mp) { auto ys = p.Y; ans += uf.size(ys[0]) - ys.size(); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, x, n) for (int i = x; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(X) (X).begin(), (X).end() #define X first #define Y second #define pb push_back #define eb emplace_back using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; 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; } template <class A, size_t N, class T> void Fill(A (&a)[N], const T &v) { fill((T *)a, (T *)(a + N), v); } template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "{"; rep(i, t.size()) { os << t[i] << ","; } os << "}"; return os; } template <class T, size_t n> ostream &operator<<(ostream &os, const array<T, n> &t) { os << "{"; rep(i, n) { os << t[i] << ","; } os << "}"; return os; } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) { return os << "(" << t.first << "," << t.second << ")"; } const ll INF = 1e9 + 7; struct UnionFind { std::vector<int> data; // dataの各要素について // 負の値:その集合のルートであること示す。また、その絶対値は集合の要素数となっている。 // 正の値:親ノードの番号(dataのインデックス)。root()を呼び出すたびに集合のルートを指すように書きなおされるので木はそんなに深くならない // 初期化 size:最大要素数 UnionFind(int size) : data(size, -1) {} // 集合を併合する // すでに同じ集合だった場合は、falseが返る bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { // 要素数の大きな方へ合併するためのswap if (data[y] < data[x]) std::swap(x, y); // 要素数を加算する data[x] += data[y]; // yの属する集合のルートをxに変更 data[y] = x; } return x != y; } // 同じ集合かどうか判定 bool find(int x, int y) { return root(x) == root(y); } // 集合の識別番号を返す int root(int x) { // 負の値を持つものがその集合のルート // 正の値は同じ集合に属するものを指す(辿ればいずれルートへ着く) return (data[x] < 0) ? x : data[x] = root(data[x]); } // 集合の要素数を返す int size(int x) { return -data[root(x)]; } }; int main() { ios_base::sync_with_stdio(false); ll N, ans = 0; map<int, vector<int>> mp; cin >> N; rep(i, N) { int x, y; cin >> x >> y; mp[x].push_back(y); } UnionFind uf(200005); for (auto p : mp) { auto ys = p.Y; for (int y : ys) uf.unite(ys[0], y); } for (auto p : mp) { auto ys = p.Y; ans += uf.size(ys[0]) - ys.size(); } cout << ans << endl; return 0; }
replace
108
109
108
109
0
p02998
C++
Runtime Error
#include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> #include <string> #include <vector> using namespace std; typedef long long ll; const ll mod = 1000000007; class mint { public: ll x; mint(ll x = 0) : x(x % mod) {} mint &operator+=(const mint rhs) { x += rhs.x; while (x >= mod) x -= mod; return *this; } mint &operator-=(const mint rhs) { x -= rhs.x; while (x < 0) x += mod; return *this; } mint &operator*=(const mint rhs) { (x *= rhs.x) %= mod; return *this; } mint operator+(const mint rhs) const { mint res(*this); return res += rhs; } mint operator-(const mint rhs) const { mint res(*this); return res -= rhs; } mint operator*(const mint rhs) const { mint res(*this); return res *= rhs; } friend ostream &operator<<(ostream &os, const mint rhs) { os << rhs.x; return os; } }; #define rep(index, num) for (int index = 0; index < num; ++index) const int V = 100000; vector<int> to[V * 2]; bool visited[V * 2]; vector<int> cnt; void dfs(int v) { if (visited[v]) return; visited[v] = true; cnt[v / V]++; for (int u : to[v]) dfs(u); } int main() { int n; std::cin >> n; rep(i, n) { int x, y; cin >> x >> y; y += V; to[x].push_back(y); to[y].push_back(x); } ll ans = 0; rep(i, V * 2) { if (visited[i]) continue; cnt = vector<int>(2); dfs(i); ans += (ll)cnt[0] * cnt[1]; } ans -= n; cout << ans << endl; return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> #include <string> #include <vector> using namespace std; typedef long long ll; const ll mod = 1000000007; class mint { public: ll x; mint(ll x = 0) : x(x % mod) {} mint &operator+=(const mint rhs) { x += rhs.x; while (x >= mod) x -= mod; return *this; } mint &operator-=(const mint rhs) { x -= rhs.x; while (x < 0) x += mod; return *this; } mint &operator*=(const mint rhs) { (x *= rhs.x) %= mod; return *this; } mint operator+(const mint rhs) const { mint res(*this); return res += rhs; } mint operator-(const mint rhs) const { mint res(*this); return res -= rhs; } mint operator*(const mint rhs) const { mint res(*this); return res *= rhs; } friend ostream &operator<<(ostream &os, const mint rhs) { os << rhs.x; return os; } }; #define rep(index, num) for (int index = 0; index < num; ++index) const int V = 100005; vector<int> to[V * 2]; bool visited[V * 2]; vector<int> cnt; void dfs(int v) { if (visited[v]) return; visited[v] = true; cnt[v / V]++; for (int u : to[v]) dfs(u); } int main() { int n; std::cin >> n; rep(i, n) { int x, y; cin >> x >> y; y += V; to[x].push_back(y); to[y].push_back(x); } ll ans = 0; rep(i, V * 2) { if (visited[i]) continue; cnt = vector<int>(2); dfs(i); ans += (ll)cnt[0] * cnt[1]; } ans -= n; cout << ans << endl; return 0; }
replace
56
57
56
57
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll N; map<ll, vector<ll>> XY; // y, x map<ll, ll> YX; map<ll, ll> Par, Rank; // root x, (#x's, ys) map<ll, pair<ll, set<ll>>> Rect; ll R; ll find(ll x) { if (!Par.count(x)) return x; return Par[x] = find(Par[x]); } void merge(ll x, ll x2) { x = find(x); x2 = find(x2); if (Rank[x] > Rank[x2]) { Par[x2] = x; } else { Par[x] = x2; if (Rank[x] == Rank[x2]) ++Rank[x2]; } } int main() { cin >> N; for (ll i = 0; i < N; ++i) { ll x, y; cin >> x >> y; XY[x].push_back(y); } for (const auto &x_ys : XY) { ll x = x_ys.first; for (ll y : x_ys.second) { if (YX.count(y)) merge(x, YX[y]); YX[y] = x; } } for (const auto &x_ys : XY) { ll x = find(x_ys.first); ++Rect[x].first; for (ll y : x_ys.second) Rect[x].second.insert(y); } for (const auto &x_rect : Rect) { const auto &rect = x_rect.second; R += rect.first * rect.second.size(); } R -= N; cout << R << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll N; map<ll, vector<ll>> XY; // y, x map<ll, ll> YX; map<ll, ll> Par, Rank; // root x, (#x's, ys) map<ll, pair<ll, set<ll>>> Rect; ll R; ll find(ll x) { if (!Par.count(x)) return x; return Par[x] = find(Par[x]); } void merge(ll x, ll x2) { x = find(x); x2 = find(x2); if (x == x2) return; if (Rank[x] > Rank[x2]) { Par[x2] = x; } else { Par[x] = x2; if (Rank[x] == Rank[x2]) ++Rank[x2]; } } int main() { cin >> N; for (ll i = 0; i < N; ++i) { ll x, y; cin >> x >> y; XY[x].push_back(y); } for (const auto &x_ys : XY) { ll x = x_ys.first; for (ll y : x_ys.second) { if (YX.count(y)) merge(x, YX[y]); YX[y] = x; } } for (const auto &x_ys : XY) { ll x = find(x_ys.first); ++Rect[x].first; for (ll y : x_ys.second) Rect[x].second.insert(y); } for (const auto &x_rect : Rect) { const auto &rect = x_rect.second; R += rect.first * rect.second.size(); } R -= N; cout << R << endl; return 0; }
insert
25
25
25
27
0
p02998
C++
Runtime Error
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> using namespace std; using namespace std::chrono; typedef long long int llint; typedef double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod = 998244353; const llint big = 2.19e17 + 1; const long double pai = 3.141592653589793238462643383279502884197; const long double eps = 1e-15; template <class T, class U> bool mineq(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> bool maxeq(T &a, U b) { if (a < b) { a = b; return true; } return false; } llint gcd(llint a, llint b) { if (a % b == 0) { return b; } else return gcd(b, a % b); } llint lcm(llint a, llint b) { if (a == 0) { return b; } return a / gcd(a, b) * b; } template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); } template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); } template <class T> llint LBI(vector<T> &ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); } template <class T> llint UBI(vector<T> &ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); } /// 2009~ int main(void) { int n, i, j; cin >> n; vector<vector<int>> tate(100001); vector<vector<int>> yoko(100001); vector<int> xz(n); vector<int> yz(n); for (i = 0; i < n; i++) { int x, y; cin >> x >> y; xz[i] = x; yz[i] = y; tate[x].pub(i); yoko[y].pub(i); } vector<vector<int>> go(n); for (int x = 1; x <= 100000; x++) { for (i = 1; i < tate[x].size(); i++) { go[tate[x][i]].pub(tate[x][i - 1]); go[tate[x][i - 1]].pub(tate[x][i]); } for (i = 1; i < tate[x].size(); i++) { go[yoko[x][i]].pub(yoko[x][i - 1]); go[yoko[x][i - 1]].pub(yoko[x][i]); } } vector<bool> mita(n); llint ans = -n; for (i = 0; i < n; i++) { // cerr<<"de"<<endl; if (mita[i]) { continue; } set<int> A, B; queue<int> que; que.push(i); while (que.size()) { int t = que.front(); que.pop(); if (mita[t]) { continue; } mita[t] = 1; A.ins(xz[t]); B.ins(yz[t]); for (auto it : go[t]) { que.push(it); } } ans += (llint)A.size() * B.size(); } cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> using namespace std; using namespace std::chrono; typedef long long int llint; typedef double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod = 998244353; const llint big = 2.19e17 + 1; const long double pai = 3.141592653589793238462643383279502884197; const long double eps = 1e-15; template <class T, class U> bool mineq(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> bool maxeq(T &a, U b) { if (a < b) { a = b; return true; } return false; } llint gcd(llint a, llint b) { if (a % b == 0) { return b; } else return gcd(b, a % b); } llint lcm(llint a, llint b) { if (a == 0) { return b; } return a / gcd(a, b) * b; } template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); } template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); } template <class T> llint LBI(vector<T> &ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); } template <class T> llint UBI(vector<T> &ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); } /// 2009~ int main(void) { int n, i, j; cin >> n; vector<vector<int>> tate(100001); vector<vector<int>> yoko(100001); vector<int> xz(n); vector<int> yz(n); for (i = 0; i < n; i++) { int x, y; cin >> x >> y; xz[i] = x; yz[i] = y; tate[x].pub(i); yoko[y].pub(i); } vector<vector<int>> go(n); for (int x = 1; x <= 100000; x++) { for (i = 1; i < tate[x].size(); i++) { go[tate[x][i]].pub(tate[x][i - 1]); go[tate[x][i - 1]].pub(tate[x][i]); } for (i = 1; i < yoko[x].size(); i++) { go[yoko[x][i]].pub(yoko[x][i - 1]); go[yoko[x][i - 1]].pub(yoko[x][i]); } } vector<bool> mita(n); llint ans = -n; for (i = 0; i < n; i++) { // cerr<<"de"<<endl; if (mita[i]) { continue; } set<int> A, B; queue<int> que; que.push(i); while (que.size()) { int t = que.front(); que.pop(); if (mita[t]) { continue; } mita[t] = 1; A.ins(xz[t]); B.ins(yz[t]); for (auto it : go[t]) { que.push(it); } } ans += (llint)A.size() * B.size(); } cout << ans << endl; return 0; }
replace
98
99
98
99
-11
p02998
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; #define DEBUG_ //!!提出時にコメントアウト!! #ifdef DEBUG_ #define dump(x) cerr << #x << " = " << (x) << endl; #else #define dump(x) ; #endif #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back // #define int long long 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<LL, LL> PLL; template <typename T> std::string printVector(const std::vector<T> &data) { std::stringstream ss; std::ostream_iterator<T> out_it(ss, ", "); ss << "["; std::copy(data.begin(), data.end() - 1, out_it); ss << data.back() << "]"; return ss.str(); } const int MOD = 1e9 + 7; const LL LINF = 1001002003004005006ll; const int INF = 1001001001; const int MAX_N = 10010; vector<int> adj[MAX_N * 2]; bool visited[MAX_N * 2] = {}; VL cnt; void dfs(int v) { if (visited[v] == 1) return; visited[v] = 1; cnt[v / MAX_N]++; for (int p : adj[v]) { dfs(p); } } signed main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; REP(i, N) { int x, y; cin >> x >> y; y += MAX_N; adj[x].eb(y); adj[y].eb(x); } LL ans = 0; for (int i = 0; i < MAX_N * 2; i++) { if (visited[i] == 1) continue; cnt = VL(2, 0); dfs(i); ans += cnt[0] * cnt[1]; } cout << ans - N << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; #define DEBUG_ //!!提出時にコメントアウト!! #ifdef DEBUG_ #define dump(x) cerr << #x << " = " << (x) << endl; #else #define dump(x) ; #endif #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back // #define int long long 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<LL, LL> PLL; template <typename T> std::string printVector(const std::vector<T> &data) { std::stringstream ss; std::ostream_iterator<T> out_it(ss, ", "); ss << "["; std::copy(data.begin(), data.end() - 1, out_it); ss << data.back() << "]"; return ss.str(); } const int MOD = 1e9 + 7; const LL LINF = 1001002003004005006ll; const int INF = 1001001001; const int MAX_N = 100010; vector<int> adj[MAX_N * 2]; bool visited[MAX_N * 2] = {}; VL cnt; void dfs(int v) { if (visited[v] == 1) return; visited[v] = 1; cnt[v / MAX_N]++; for (int p : adj[v]) { dfs(p); } } signed main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; REP(i, N) { int x, y; cin >> x >> y; y += MAX_N; adj[x].eb(y); adj[y].eb(x); } LL ans = 0; for (int i = 0; i < MAX_N * 2; i++) { if (visited[i] == 1) continue; cnt = VL(2, 0); dfs(i); ans += cnt[0] * cnt[1]; } cout << ans - N << endl; }
replace
57
58
57
58
0
p02998
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n - 1); i >= 0; i--) #define REP1(i, n) for (int i = 1; i <= (n); i++) #define RREP1(i, n) for (int i = (n); i >= 1; i--) #define ALL(a) (a).begin(), (a).end() #define UNIQUE_SORT(l) \ sort(ALL(l)); \ l.erase(unique(ALL(l)), l.end()); #define CONTAIN(a, b) find(ALL(a), (b)) != (a).end() #define out(...) printf(__VA_ARGS__) #if DEBUG #define debug(...) printf(__VA_ARGS__) #else #define debug(...) /* ... */ #endif 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; } void _OUT(){}; template <class H, class... T> void _OUT(H &h, T &...t) { cout << ' ' << h; _OUT(t...); }; template <class H, class... T> void _P(H &h, T &...t) { cout << h; _OUT(t...); }; #define _PN(...) \ _P(__VA_ARGS__); \ cout << endl; #define EXEC(...) \ void exec() { (__VA_ARGS__ - 1) ? multi() : solve(0); } void exec(); void solve(int t); void multi() { int TT; cin >> TT; REP1(t, TT) solve(t); } signed main() { #if DEBUG std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif cin.tie(0); ios::sync_with_stdio(false); exec(); return 0; } /*================================*/ #if DEBUG #define SIZE 123450 #else #define SIZE 123450 #endif int N, M; vector<int> A(SIZE); struct UnionFind { vector<int> parent; int size; vector<set<int>> V; UnionFind(int size) { reset(size); } void reset(int size) { this->size = size; parent.resize(size); REP(i, size) parent[i] = i; V.resize(size); REP(i, size) V[i].insert(i); } int root(int i) { if (parent[i] == i) return i; return parent[i] = root(parent[i]); } void merge(int i, int j) { int ir = root(i); int jr = root(j); if (ir == jr) return; int next = (V[ir].size() <= V[jr].size()) ? ir : jr; int hide = (ir == next) ? jr : ir; parent[ir] = parent[jr] = next; for (int n : V[hide]) V[next].insert(n); V[hide].clear(); } bool same(int i, int j) { return root(i) == root(j); } int vsize(int i) { return (int)V[i].size(); } }; void solve(int _t) { cin >> N; auto uf = new UnionFind(SIZE); int x, y; set<int> ylist[SIZE]; vector<pair<int, int>> V; REP(i, N) { cin >> x >> y; ylist[x].insert(y); V.push_back({x, y}); } REP(i, SIZE) if (ylist[i].size()) { int y0 = *ylist[i].begin(); for (int y : ylist[i]) { uf->merge(y0, y); } } vector<set<int>> xlist(SIZE); for (auto p : V) { xlist[uf->root(p.second)].insert(p.first); debug("xlist[%lld].insert(%lld)\n", uf->root(p.second), p.first); } int ans = -N; REP(i, SIZE) { ans += xlist[i].size() * uf->vsize(i); } _PN(ans); } EXEC(1)
#include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n - 1); i >= 0; i--) #define REP1(i, n) for (int i = 1; i <= (n); i++) #define RREP1(i, n) for (int i = (n); i >= 1; i--) #define ALL(a) (a).begin(), (a).end() #define UNIQUE_SORT(l) \ sort(ALL(l)); \ l.erase(unique(ALL(l)), l.end()); #define CONTAIN(a, b) find(ALL(a), (b)) != (a).end() #define out(...) printf(__VA_ARGS__) #if DEBUG #define debug(...) printf(__VA_ARGS__) #else #define debug(...) /* ... */ #endif 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; } void _OUT(){}; template <class H, class... T> void _OUT(H &h, T &...t) { cout << ' ' << h; _OUT(t...); }; template <class H, class... T> void _P(H &h, T &...t) { cout << h; _OUT(t...); }; #define _PN(...) \ _P(__VA_ARGS__); \ cout << endl; #define EXEC(...) \ void exec() { (__VA_ARGS__ - 1) ? multi() : solve(0); } void exec(); void solve(int t); void multi() { int TT; cin >> TT; REP1(t, TT) solve(t); } signed main() { #if DEBUG std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif cin.tie(0); ios::sync_with_stdio(false); exec(); return 0; } /*================================*/ #if DEBUG #define SIZE 123450 #else #define SIZE 123450 #endif int N, M; vector<int> A(SIZE); struct UnionFind { vector<int> parent; int size; vector<set<int>> V; UnionFind(int size) { reset(size); } void reset(int size) { this->size = size; parent.resize(size); REP(i, size) parent[i] = i; V.resize(size); REP(i, size) V[i].insert(i); } int root(int i) { if (parent[i] == i) return i; return parent[i] = root(parent[i]); } void merge(int i, int j) { int ir = root(i); int jr = root(j); if (ir == jr) return; int next = (V[ir].size() >= V[jr].size()) ? ir : jr; int hide = (ir == next) ? jr : ir; parent[ir] = parent[jr] = next; for (int n : V[hide]) V[next].insert(n); V[hide].clear(); } bool same(int i, int j) { return root(i) == root(j); } int vsize(int i) { return (int)V[i].size(); } }; void solve(int _t) { cin >> N; auto uf = new UnionFind(SIZE); int x, y; set<int> ylist[SIZE]; vector<pair<int, int>> V; REP(i, N) { cin >> x >> y; ylist[x].insert(y); V.push_back({x, y}); } REP(i, SIZE) if (ylist[i].size()) { int y0 = *ylist[i].begin(); for (int y : ylist[i]) { uf->merge(y0, y); } } vector<set<int>> xlist(SIZE); for (auto p : V) { xlist[uf->root(p.second)].insert(p.first); debug("xlist[%lld].insert(%lld)\n", uf->root(p.second), p.first); } int ans = -N; REP(i, SIZE) { ans += xlist[i].size() * uf->vsize(i); } _PN(ans); } EXEC(1)
replace
99
100
99
100
TLE
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int ll #define ll long long #define I32_MAX 2147483647 #define I64_MAX 9223372036854775807LL #define I64_MAX2 1223372036854775807LL #define INF I64_MAX2 #define MOD 1000000007 // #define MOD 998244353 #define MEM_SIZE 101010 #define DEBUG_OUT true #define ALL(x) (x).begin(), (x).end() template <typename T> void DEBUG(T e) { if (DEBUG_OUT == false) return; std::cout << e << " "; } template <typename T> void DEBUG(const std::vector<T> &v) { if (DEBUG_OUT == false) return; for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) { if (DEBUG_OUT == false) return; for (const auto &v : vv) { DEBUG(v); } } template <class T, class... Ts> void DEBUG(T d, Ts... e) { if (DEBUG_OUT == false) return; DEBUG(d); DEBUG(e...); } template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; abort(); } } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } const int V = 10101; vector<int> to[V * 2]; bool visited[V * 2]; vector<int> cnt; void dfs(int v) { if (visited[v]) return; visited[v] = true; cnt[v / V]++; for (auto &&u : to[v]) { dfs(u); } } void solve(void) { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; y += V; to[x].push_back(y); to[y].push_back(x); } int res = 0; for (int i = 0; i < V * 2; i++) { if (visited[i]) continue; cnt = vector<int>(2); dfs(i); res += cnt[0] * cnt[1]; } res -= n; cout << res << endl; return; } int32_t main(int32_t argc, const char *argv[]) { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed; std::cout << std::setprecision(11); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int ll #define ll long long #define I32_MAX 2147483647 #define I64_MAX 9223372036854775807LL #define I64_MAX2 1223372036854775807LL #define INF I64_MAX2 #define MOD 1000000007 // #define MOD 998244353 #define MEM_SIZE 101010 #define DEBUG_OUT true #define ALL(x) (x).begin(), (x).end() template <typename T> void DEBUG(T e) { if (DEBUG_OUT == false) return; std::cout << e << " "; } template <typename T> void DEBUG(const std::vector<T> &v) { if (DEBUG_OUT == false) return; for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) { if (DEBUG_OUT == false) return; for (const auto &v : vv) { DEBUG(v); } } template <class T, class... Ts> void DEBUG(T d, Ts... e) { if (DEBUG_OUT == false) return; DEBUG(d); DEBUG(e...); } template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; abort(); } } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } const int V = 101010; vector<int> to[V * 2]; bool visited[V * 2]; vector<int> cnt; void dfs(int v) { if (visited[v]) return; visited[v] = true; cnt[v / V]++; for (auto &&u : to[v]) { dfs(u); } } void solve(void) { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; y += V; to[x].push_back(y); to[y].push_back(x); } int res = 0; for (int i = 0; i < V * 2; i++) { if (visited[i]) continue; cnt = vector<int>(2); dfs(i); res += cnt[0] * cnt[1]; } res -= n; cout << res << endl; return; } int32_t main(int32_t argc, const char *argv[]) { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed; std::cout << std::setprecision(11); solve(); return 0; }
replace
53
54
53
54
0
p02998
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vii vector<int> #define vll vector<ll> #define lb lower_bound #define pb push_back #define mp make_pair #define rep(i, n) for (ll i = 0; i < n; i++) #define rep2(i, a, b) for (ll i = a; i < b; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(), x.end() #define INF (1 << 30) - 1 #define LLINF (1LL << 61) - 1 #define int ll using namespace std; const int MOD = 1000000007; const int MAX = 510000; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[find(x)]; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; ll ans = 0; vii x, y; const int MAX = 11000; cin >> n; x.resize(n); y.resize(n); UnionFind uf(MAX * 2); rep(i, n) { cin >> x[i] >> y[i]; uf.unite(x[i], y[i] + MAX); } map<int, ll> mx, my; rep(i, MAX) { mx[uf.find(i)]++; } rep2(i, MAX, MAX * 2) { my[uf.find(i)]++; } rep(i, MAX * 2) { ans += mx[i] * my[i]; } cout << ans - n << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vii vector<int> #define vll vector<ll> #define lb lower_bound #define pb push_back #define mp make_pair #define rep(i, n) for (ll i = 0; i < n; i++) #define rep2(i, a, b) for (ll i = a; i < b; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(), x.end() #define INF (1 << 30) - 1 #define LLINF (1LL << 61) - 1 #define int ll using namespace std; const int MOD = 1000000007; const int MAX = 510000; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[find(x)]; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; ll ans = 0; vii x, y; const int MAX = 110000; cin >> n; x.resize(n); y.resize(n); UnionFind uf(MAX * 2); rep(i, n) { cin >> x[i] >> y[i]; uf.unite(x[i], y[i] + MAX); } map<int, ll> mx, my; rep(i, MAX) { mx[uf.find(i)]++; } rep2(i, MAX, MAX * 2) { my[uf.find(i)]++; } rep(i, MAX * 2) { ans += mx[i] * my[i]; } cout << ans - n << endl; return 0; }
replace
71
72
71
72
0
p02998
C++
Runtime Error
// #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; #define ll long long #define debug(x) cerr << "\n" << #x << ": " << x << "\n" #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define all(x) (x).begin(), (x).end() #define int long long #define INF 1e9 #define pii pair<int, int> #define pt(xx) cout << "\n" << xx << "\n" #define debugv(x, n) \ cout << "\n" << #x << ": "; \ rep(i, n) cout << x[i] << " "; \ cout << endl #define debug2d(x, m, n) \ cout << "\n" << #x << " is: \n"; \ for (int i = 0; i < m; ++i) { \ for (int j = 0; j < n; ++j) { \ cout << x[i][j] << " "; \ } \ cout << endl; \ } #define nl cout << endl #define MOD 1000000007 int N, K, L; int ans; const int V = 10005; vector<vector<int>> v(2 * V); vector<int> visited(2 * V, 0); int cnt[2]; void dfs(int n) { if (visited[n]) return; visited[n] = 1; if (n < V) cnt[0]++; else cnt[1]++; for (auto x : v[n]) { dfs(x); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); //============================================== ans = 0; cin >> N; int x, y; rep(i, N) { cin >> x >> y; y = y + V; v[x].push_back(y); v[y].push_back(x); } rep(i, 2 * V) { // if(v[i].size() < 1)continue; if (visited[i]) continue; cnt[0] = 0; cnt[1] = 0; dfs(i); ans += cnt[0] * cnt[1]; } ans -= N; cout << ans << endl; return 0; }
// #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; #define ll long long #define debug(x) cerr << "\n" << #x << ": " << x << "\n" #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define all(x) (x).begin(), (x).end() #define int long long #define INF 1e9 #define pii pair<int, int> #define pt(xx) cout << "\n" << xx << "\n" #define debugv(x, n) \ cout << "\n" << #x << ": "; \ rep(i, n) cout << x[i] << " "; \ cout << endl #define debug2d(x, m, n) \ cout << "\n" << #x << " is: \n"; \ for (int i = 0; i < m; ++i) { \ for (int j = 0; j < n; ++j) { \ cout << x[i][j] << " "; \ } \ cout << endl; \ } #define nl cout << endl #define MOD 1000000007 int N, K, L; int ans; const int V = 100005; vector<vector<int>> v(2 * V); vector<int> visited(2 * V, 0); int cnt[2]; void dfs(int n) { if (visited[n]) return; visited[n] = 1; if (n < V) cnt[0]++; else cnt[1]++; for (auto x : v[n]) { dfs(x); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); //============================================== ans = 0; cin >> N; int x, y; rep(i, N) { cin >> x >> y; y = y + V; v[x].push_back(y); v[y].push_back(x); } rep(i, 2 * V) { // if(v[i].size() < 1)continue; if (visited[i]) continue; cnt[0] = 0; cnt[1] = 0; dfs(i); ans += cnt[0] * cnt[1]; } ans -= N; cout << ans << endl; return 0; }
replace
39
40
39
40
0
p02998
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 5; int fa[N]; int n1[N], n2[N]; vector<int> edge[N]; int Find(int v) { return v == fa[v] ? v : fa[v] == Find(fa[v]); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m = 0; cin >> n; for (int i = 0; i < n; ++i) { int u, v; cin >> u >> v; m = max(m, max(u, v)); edge[u].push_back(v); } for (int i = 1; i <= m; ++i) { fa[i] = i; n1[i] = 0; n2[i] = 1; } for (int i = 1; i <= m; ++i) { int len = edge[i].size(); if (len == 0) continue; int pa = Find(edge[i][0]); n1[pa]++; for (int j = 1; j < len; ++j) { int v = edge[i][j]; int pa2 = Find(v); if (pa != pa2) { fa[pa2] = pa; n1[pa] += n1[pa2]; n2[pa] += n2[pa2]; } } } ll ans = 0; for (int i = 1; i <= m; ++i) { if (fa[i] == i) { ans += 1ll * n1[i] * n2[i]; } } cout << ans - 1ll * n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 5; int fa[N]; int n1[N], n2[N]; vector<int> edge[N]; int Find(int v) { return v == fa[v] ? v : fa[v] = Find(fa[v]); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m = 0; cin >> n; for (int i = 0; i < n; ++i) { int u, v; cin >> u >> v; m = max(m, max(u, v)); edge[u].push_back(v); } for (int i = 1; i <= m; ++i) { fa[i] = i; n1[i] = 0; n2[i] = 1; } for (int i = 1; i <= m; ++i) { int len = edge[i].size(); if (len == 0) continue; int pa = Find(edge[i][0]); n1[pa]++; for (int j = 1; j < len; ++j) { int v = edge[i][j]; int pa2 = Find(v); if (pa != pa2) { fa[pa2] = pa; n1[pa] += n1[pa2]; n2[pa] += n2[pa2]; } } } ll ans = 0; for (int i = 1; i <= m; ++i) { if (fa[i] == i) { ans += 1ll * n1[i] * n2[i]; } } cout << ans - 1ll * n << endl; return 0; }
replace
11
12
11
12
0
p02999
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> II; typedef vector<II> VII; typedef vector<int> VI; typedef vector<VI> VVI; typedef long long int LL; typedef unsigned long long int ULL; #define PB push_back #define MP make_pair #define F first #define S second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(), a.end() #define SET(a, b) memset(a, b, sizeof(a)) #define LET(x, a) __typeof(a) x(a) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // Works for forward as well as backward iteration #define gu getchar #define pu putchar #define si(n) scanf("%d", &n) #define dout(n) printf("%d\n", n) #define sll(n) scanf("%lld", &n) #define lldout(n) printf("%lld\n", n) #define DRT() \ int t; \ si(t); \ while (t--) #define PlUSWRAP(index, n) \ index = (index + 1) % n // index++; if(index>=n) index=0 #define MINUSWRAP(index, n) \ index = (index + n - 1) % n // index--; if(index<0) index=n-1 #define ROUNDOFFINT(d) \ d = (int)((double)d + 0.5) // Round off d to nearest integer #define FLUSHN while (gu() != '\n') #define FLUSHS while (gu() != ' ') #define TRACE #ifdef TRACE #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #else #define trace1(x) #define trace2(x, y) #define trace3(x, y, z) #define trace4(a, b, c, d) #define trace5(a, b, c, d, e) #define trace6(a, b, c, d, e, f) #endif #define off \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif off; int x, a; cin >> x >> a; if (x < a) cout << 0; else cout << 10; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> II; typedef vector<II> VII; typedef vector<int> VI; typedef vector<VI> VVI; typedef long long int LL; typedef unsigned long long int ULL; #define PB push_back #define MP make_pair #define F first #define S second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(), a.end() #define SET(a, b) memset(a, b, sizeof(a)) #define LET(x, a) __typeof(a) x(a) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // Works for forward as well as backward iteration #define gu getchar #define pu putchar #define si(n) scanf("%d", &n) #define dout(n) printf("%d\n", n) #define sll(n) scanf("%lld", &n) #define lldout(n) printf("%lld\n", n) #define DRT() \ int t; \ si(t); \ while (t--) #define PlUSWRAP(index, n) \ index = (index + 1) % n // index++; if(index>=n) index=0 #define MINUSWRAP(index, n) \ index = (index + n - 1) % n // index--; if(index<0) index=n-1 #define ROUNDOFFINT(d) \ d = (int)((double)d + 0.5) // Round off d to nearest integer #define FLUSHN while (gu() != '\n') #define FLUSHS while (gu() != ' ') #define TRACE #ifdef TRACE #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #else #define trace1(x) #define trace2(x, y) #define trace3(x, y, z) #define trace4(a, b, c, d) #define trace5(a, b, c, d, e) #define trace6(a, b, c, d, e, f) #endif #define off \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif off; int x, a; cin >> x >> a; if (x < a) cout << 0; else cout << 10; return 0; }
replace
83
87
83
87
0
p02999
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define f first #define s second #define PB push_back #define MP make_pair #define db long double #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define cases \ int testcases; \ cin >> testcases; \ while (testcases--) #define MOD 1000000007 int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { if (a.s == b.s) { return a.f < b.f; } return a.s < b.s; } int32_t main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif IOS int x, a; cin >> x >> a; if (x < a) { cout << 0; } else { cout << 10; } return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define f first #define s second #define PB push_back #define MP make_pair #define db long double #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define cases \ int testcases; \ cin >> testcases; \ while (testcases--) #define MOD 1000000007 int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { if (a.s == b.s) { return a.f < b.f; } return a.s < b.s; } int32_t main() { IOS int x, a; cin >> x >> a; if (x < a) { cout << 0; } else { cout << 10; } return 0; }
delete
51
57
51
51
0
p02999
C++
Runtime Error
#include <stdio.h> int main(void) { int x, a, result; scanf("%d %d", x, a); if (x < a) result = 0; else result = 10; printf("%d", result); return 0; }
#include <stdio.h> int main(void) { int x, a, result; scanf("%d %d", &x, &a); if (x < a) result = 0; else result = 10; printf("%d", result); return 0; }
replace
4
5
4
5
-11
p02999
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define ok() puts(ok ? "Yes" : "No"); using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<bool> vb; typedef vector<vb> vvb; typedef set<int> si; typedef map<string, int> msi; typedef greater<int> gt; typedef priority_queue<int, vector<int>, gt> minq; typedef long long ll; typedef pair<ll, ll> pll; const ll LINF = 1e18L + 1; const int INF = 1e9 + 1; // clang++ -std=c++11 -stdlib=libc++ int main() { int x, a; cin >> x >> a; cout << x / a * 10 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define ok() puts(ok ? "Yes" : "No"); using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<bool> vb; typedef vector<vb> vvb; typedef set<int> si; typedef map<string, int> msi; typedef greater<int> gt; typedef priority_queue<int, vector<int>, gt> minq; typedef long long ll; typedef pair<ll, ll> pll; const ll LINF = 1e18L + 1; const int INF = 1e9 + 1; // clang++ -std=c++11 -stdlib=libc++ int main() { int x, a; cin >> x >> a; int ans = 10; if (x < a) ans = 0; cout << ans << endl; return 0; }
replace
24
25
24
28
0
p02999
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int X, A; cin >> X >> A; cout << X / A * 10 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int X, A; cin >> X >> A; if (X < A) { cout << 0 << endl; } else { cout << 10 << endl; } }
replace
6
7
6
11
0
p02999
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << ((int)(a / b) * 10) << endl; }
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << (a >= b ? 10 : 0) << endl; }
replace
8
9
8
9
0
p02999
C++
Runtime Error
#include <stdio.h> int main(void) { int a, x; scanf("%d %d", a, x); if (x < a) { printf("0"); } else { printf("10"); } return 0; }
#include <stdio.h> int main(void) { int a, x; scanf("%d %d", &a, &x); if (x > a) { printf("0"); } else { printf("10"); } return 0; }
replace
3
5
3
5
-11
p02999
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { int X, A; cin >> X >> A; cout << ((X / A) ? 1 : 0) * 10 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int X, A; cin >> X >> A; if (X < A) cout << "0\n"; else cout << "10\n"; return 0; }
replace
7
8
7
12
0
p02999
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <string> #include <vector> using namespace std; int main() { int x, a; cin >> x >> a; if (x / a == 0) { cout << 0 << endl; } else { cout << 10 << endl; } }
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <string> #include <vector> using namespace std; int main() { int x, a; cin >> x >> a; if (a == 0) { cout << 10 << endl; } else if (x / a == 0) { cout << 0 << endl; } else { cout << 10 << endl; } }
replace
12
13
12
15
0
p02999
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using P = pair<int, int>; using PL = pair<ll, ll>; using vp = vector<P>; using vpl = vector<PL>; constexpr const int INF = 1 << 30, MOD = 1000000007; constexpr const ll LINF = 1ll << 60; #define _ol3(_1, _2, _3, name, ...) name #define _rep(i, n) _repi(i, 0, n) #define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i) #define REP(...) _ol3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, v) REP(i, v.size()) #define all(v) (v).begin(), (v).end() #define bit(n) (1ll << (n)) #define uniq(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()) #define F first #define S second #define endl '\n' #define cho(n, a, b) cout << ((n) ? a : b) << endl void YES(int n) { cho(n, "YES", "NO"); } void Yes(int n) { cho(n, "Yes", "No"); } void Poss(int n) { cho(n, "Possible", "Impossible"); } #ifndef LOCAL struct osd { template <class T> osd &operator<(const T &t) { return *this; } template <class T> osd &operator<<(const T &t) { return *this; } }; osd cer_; template <class... T> void _print(osd &a, T &&...t) {} #define cerr cer_ #endif template <class T> ostream &operator<(ostream &o, const T &t) { return o << t; } template <class T> istream &operator>(istream &i, T &t) { return i >> t; } void _print(ostream &s) {} template <class T, class... U> void _print(ostream &s, T &&t, U &&...u) { s < t < (sizeof...(u) ? ' ' : '\n'); _print(s, u...); } template <class... T> void print(T &&...t) { _print(cout, t...); } template <class... T> void dprint(T &&...t) { _print(cerr, t...); } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { for (auto &&i : v) o < i < ' '; return o; } template <class T> istream &operator>>(istream &i, vector<T> &v) { for (T &j : v) i > j; return i; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &p) { return o < p.F < ' ' < p.S; } template <class T, class U> istream &operator>>(istream &i, pair<T, U> &p) { return i > p.F > p.S; } template <class T> ostream &operator<<(ostream &o, const set<T> &v) { for (auto &&i : v) o < i < ' '; return o; } template <class T> vector<T> &operator<<(vector<T> &v, const T &t) { v.push_back(t); return v; } template <class T> queue<T> &operator<<(queue<T> &q, const T &t) { q.push(t); return q; } template <class T> queue<T> &operator<<(T &t, queue<T> &q) { t = q.front(); q.pop(); return q; } template <class T> deque<T> &operator>>(const T &t, deque<T> &q) { q.push_front(t); return q; } template <class T> deque<T> &operator<<(T &t, deque<T> &q) { t = q.front(); q.pop_front(); return q; } template <class T> deque<T> &operator<<(deque<T> &q, const T &t) { q.push_back(t); return q; } template <class T> deque<T> &operator>>(deque<T> &q, T &t) { t = q.back(t); q.pop_back(); return q; } template <class T> stack<T> &operator<<(stack<T> &s, const T &t) { s.push(t); return s; } template <class T> stack<T> &operator>>(stack<T> &s, T &t) { t = s.top(); s.pop(); return s; } int main() { cin.tie(0); ios::sync_with_stdio(0); int x, a; cin > x > a; cout < (x / a) * 10 < endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using P = pair<int, int>; using PL = pair<ll, ll>; using vp = vector<P>; using vpl = vector<PL>; constexpr const int INF = 1 << 30, MOD = 1000000007; constexpr const ll LINF = 1ll << 60; #define _ol3(_1, _2, _3, name, ...) name #define _rep(i, n) _repi(i, 0, n) #define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i) #define REP(...) _ol3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, v) REP(i, v.size()) #define all(v) (v).begin(), (v).end() #define bit(n) (1ll << (n)) #define uniq(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()) #define F first #define S second #define endl '\n' #define cho(n, a, b) cout << ((n) ? a : b) << endl void YES(int n) { cho(n, "YES", "NO"); } void Yes(int n) { cho(n, "Yes", "No"); } void Poss(int n) { cho(n, "Possible", "Impossible"); } #ifndef LOCAL struct osd { template <class T> osd &operator<(const T &t) { return *this; } template <class T> osd &operator<<(const T &t) { return *this; } }; osd cer_; template <class... T> void _print(osd &a, T &&...t) {} #define cerr cer_ #endif template <class T> ostream &operator<(ostream &o, const T &t) { return o << t; } template <class T> istream &operator>(istream &i, T &t) { return i >> t; } void _print(ostream &s) {} template <class T, class... U> void _print(ostream &s, T &&t, U &&...u) { s < t < (sizeof...(u) ? ' ' : '\n'); _print(s, u...); } template <class... T> void print(T &&...t) { _print(cout, t...); } template <class... T> void dprint(T &&...t) { _print(cerr, t...); } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { for (auto &&i : v) o < i < ' '; return o; } template <class T> istream &operator>>(istream &i, vector<T> &v) { for (T &j : v) i > j; return i; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &p) { return o < p.F < ' ' < p.S; } template <class T, class U> istream &operator>>(istream &i, pair<T, U> &p) { return i > p.F > p.S; } template <class T> ostream &operator<<(ostream &o, const set<T> &v) { for (auto &&i : v) o < i < ' '; return o; } template <class T> vector<T> &operator<<(vector<T> &v, const T &t) { v.push_back(t); return v; } template <class T> queue<T> &operator<<(queue<T> &q, const T &t) { q.push(t); return q; } template <class T> queue<T> &operator<<(T &t, queue<T> &q) { t = q.front(); q.pop(); return q; } template <class T> deque<T> &operator>>(const T &t, deque<T> &q) { q.push_front(t); return q; } template <class T> deque<T> &operator<<(T &t, deque<T> &q) { t = q.front(); q.pop_front(); return q; } template <class T> deque<T> &operator<<(deque<T> &q, const T &t) { q.push_back(t); return q; } template <class T> deque<T> &operator>>(deque<T> &q, T &t) { t = q.back(t); q.pop_back(); return q; } template <class T> stack<T> &operator<<(stack<T> &s, const T &t) { s.push(t); return s; } template <class T> stack<T> &operator>>(stack<T> &s, T &t) { t = s.top(); s.pop(); return s; } int main() { cin.tie(0); ios::sync_with_stdio(0); int x, a; cin > x > a; cout < ((x < a) ? 0 : 10) < endl; return 0; }
replace
124
125
124
125
0
p02999
C++
Runtime Error
#include <bits/stdc++.h> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 30; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int a, b; int main() { cin >> a >> b; cout << min(1, a / b) * 10 << endl; }
#include <bits/stdc++.h> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 30; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int a, b; int main() { cin >> a >> b; if (a >= b) cout << 10 << endl; else cout << 0 << endl; }
replace
31
32
31
35
0
p02999
C++
Runtime Error
#include <iostream> using namespace std; int main(int argc, char *argv[]) { if (atoi(argv[1]) < atoi(argv[2])) { cout << 0; } else { cout << 10; } return 0; }
#include <iostream> using namespace std; int main(int argc, char *argv[]) { int x, a; cin >> x >> a; if (x < a) { cout << 0; } else { cout << 10; } return 0; }
replace
5
6
5
8
-11
p02999
C++
Runtime Error
#include <bits/stdc++.h> #define sz(c) int(c.size()) #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = (b)-1; i >= (a); --i) using namespace std; using ll = long long; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(10); int x, a; cin >> x >> a; cout << (x / a) * 10 << "\n"; }
#include <bits/stdc++.h> #define sz(c) int(c.size()) #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = (b)-1; i >= (a); --i) using namespace std; using ll = long long; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(10); int x, a; cin >> x >> a; cout << (x >= a) * 10 << "\n"; }
replace
14
15
14
15
0
p02999
Python
Runtime Error
x, a = map(int, input()) if x < a: print("0") if x >= a: print("10")
x, a = map(int, input().split()) if x < a: print("0") if x >= a: print("10")
replace
0
1
0
1
ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02999/Python/s299776695.py", line 1, in <module> x, a = map(int, input()) ValueError: invalid literal for int() with base 10: ' '
p02999
Python
Runtime Error
# -*- coding: utf-8 -*- x, a = int(input()), int(input()) if x < a: print("0") else: print("10")
# -*- coding: utf-8 -*- x, a = map(int, input().split()) if x < a: print("0") else: print("10")
replace
2
3
2
3
ValueError: invalid literal for int() with base 10: '3 5'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02999/Python/s027313793.py", line 3, in <module> x, a = int(input()), int(input()) ValueError: invalid literal for int() with base 10: '3 5'
p02999
Python
Runtime Error
X, A = int(input().split("")) if X < A: print(0) else: print(10)
X, A = map(int, input().split(" ")) if X < A: print(0) else: print(10)
replace
0
1
0
1
ValueError: empty separator
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02999/Python/s387668120.py", line 1, in <module> X, A = int(input().split('')) ValueError: empty separator
p02999
Python
Runtime Error
X, A = map(int, input()) if X < A: print(0) else: print(10)
X, A = map(int, input().split()) if X < A: print(0) else: print(10)
replace
0
1
0
1
ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02999/Python/s897076551.py", line 1, in <module> X, A = map(int, input()) ValueError: invalid literal for int() with base 10: ' '
p02999
Python
Runtime Error
x, a = list(input()) print("100"[x >= a :: 2])
x, a = map(int, input().split()) print(int("100"[x < a :: 2]))
replace
0
2
0
2
ValueError: too many values to unpack (expected 2)
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02999/Python/s110286285.py", line 1, in <module> x, a = list(input()) ValueError: too many values to unpack (expected 2)
p02999
Python
Runtime Error
x, a = map(int, input()) if x < a: print(0) else: print(10)
# A Rounding x, a = map(int, input().split()) if x < a: print(0) else: print(10)
replace
0
1
0
3
ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02999/Python/s947229710.py", line 1, in <module> x, a = map(int, input()) ValueError: invalid literal for int() with base 10: ' '
p02999
C++
Runtime Error
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair<ll, ll> #define vpii vector<pair<ll, ll>> #define F first #define S second #define ld long double #define built __builtin_popcountll #define mst(a, i) memset(a, i, sizeof(a)) #define all(x) x.begin(), x.end() #define itit(it, a) for (auto it = (a).begin(); it != (a).end(); it++) #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i > b; i--) #define reprr(i, a, b) for (ll i = a; i >= b; i--) #define pi 3.14159265358979323846264338327950288419716939937510582097494459230 ll max3(ll x, ll y, ll z) { return max(max(x, y), z); } ll min3(ll x, ll y, ll z) { return min(min(x, y), z); } const ll M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e17 + 10; void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl int X[] = {0, 1, 0, -1}; int Y[] = {-1, 0, 1, 0}; ll power(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % mod; x = ((x % mod) * (x % mod)) % mod; n = n / 2; } return result; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll x, a; cin >> x >> a; if (x < a) cout << 0; else cout << 10; return 0; } /* The judge is never wrong! Your code is buggy Look for: * * Read the problem carefully. * * Don't forget to sort(), mod, ll!!!! * * Initial value = +/- infinity instead of zero!!! * * an easier and alternate approach * * read the problem statement carefully * * if concept is correct and still WA, try with a different implementation * * special cases (n=1?) * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/ */
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair<ll, ll> #define vpii vector<pair<ll, ll>> #define F first #define S second #define ld long double #define built __builtin_popcountll #define mst(a, i) memset(a, i, sizeof(a)) #define all(x) x.begin(), x.end() #define itit(it, a) for (auto it = (a).begin(); it != (a).end(); it++) #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i > b; i--) #define reprr(i, a, b) for (ll i = a; i >= b; i--) #define pi 3.14159265358979323846264338327950288419716939937510582097494459230 ll max3(ll x, ll y, ll z) { return max(max(x, y), z); } ll min3(ll x, ll y, ll z) { return min(min(x, y), z); } const ll M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e17 + 10; void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl int X[] = {0, 1, 0, -1}; int Y[] = {-1, 0, 1, 0}; ll power(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % mod; x = ((x % mod) * (x % mod)) % mod; n = n / 2; } return result; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll x, a; cin >> x >> a; if (x < a) cout << 0; else cout << 10; return 0; } /* The judge is never wrong! Your code is buggy Look for: * * Read the problem carefully. * * Don't forget to sort(), mod, ll!!!! * * Initial value = +/- infinity instead of zero!!! * * an easier and alternate approach * * read the problem statement carefully * * if concept is correct and still WA, try with a different implementation * * special cases (n=1?) * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/ */
delete
65
70
65
65
0
p02999
Python
Runtime Error
x, a = map(int, input()) if x < a: print(0) else: print(10)
x, a = map(int, input().split()) if x < a: print(0) else: print(10)
replace
0
1
0
1
ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02999/Python/s478583937.py", line 1, in <module> x, a = map(int, input()) ValueError: invalid literal for int() with base 10: ' '
p03000
C++
Runtime Error
#include <algorithm> #include <fstream> #include <iostream> #include <vector> using namespace std; typedef long long ll; int main(int argc, const char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); ll n, x; cin >> n >> x; vector<ll> l(n); for (ll i = 0; i < n; i++) cin >> l[i]; vector<ll> d(n + 1); d[0] = 0; for (ll i = 1; i < n + 1; i++) d[i] = d[i - 1] + l[i - 1]; ll ind = 0; for (; d[ind] <= x; ++ind) continue; cout << ind << endl; return 0; }
#include <algorithm> #include <fstream> #include <iostream> #include <vector> using namespace std; typedef long long ll; int main(int argc, const char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); ll n, x; cin >> n >> x; vector<ll> l(n); for (ll i = 0; i < n; i++) cin >> l[i]; vector<ll> d(n + 1); d[0] = 0; for (ll i = 1; i < n + 1; i++) d[i] = d[i - 1] + l[i - 1]; ll ind = 0; for (; d[ind] <= x && ind < n + 1; ++ind) continue; cout << ind << endl; return 0; }
replace
25
26
25
26
0
p03000
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; typedef long long ll; const ll mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, X; cin >> N >> X; vector<int> L(N); REP(i, N) cin >> L.at(i); int counter = 0; int l = 0; while (counter <= X) { counter += L.at(l); l++; } cout << l << "\n"; }
#include <bits/stdc++.h> #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; typedef long long ll; const ll mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, X; cin >> N >> X; vector<int> L(N); REP(i, N) cin >> L.at(i); int counter = 0; int l = 0; while (counter <= X) { if (l >= N) { l++; break; } counter += L.at(l); l++; } cout << l << "\n"; }
insert
16
16
16
20
0
p03000
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, X; cin >> N >> X; vector<int> D(N + 1); D.at(0) = 0; for (int i = 1; i <= N + 1; i++) { int L; cin >> L; int DN = D.at(i - 1) + L; if (DN > X) { cout << i << endl; break; } else if (i == N + 1) { cout << i << endl; } D.at(i) = DN; } }
#include <bits/stdc++.h> using namespace std; int main() { int N, X; cin >> N >> X; vector<int> D(N + 2); D.at(0) = 0; for (int i = 1; i <= N + 1; i++) { int L; cin >> L; int DN = D.at(i - 1) + L; if (DN > X) { cout << i << endl; break; } else if (i == N + 1) { cout << i << endl; } D.at(i) = DN; } }
replace
7
8
7
8
0