Submission #1362090

#TimeUsernameProblemLanguageResultExecution timeMemory
1362090cholpon1A String Problem (EGOI25_stringproblem)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector <int> a(n), b(n), c(n, 0);
	bool gd = true;
	for (int i = 0; i < n; i++) {
	    cin >> a[i] >> b[i];
	    if (abs(a[i] - b[i]) != 1) gd = false;
	    c[i] = (a[i] + b[i]) % (2 * n);
	}
	vector <int> mod(2 * n, 0);
	for (int i = 0; i < n; i++) {
	   if (abs(a[i] - b[i] - 1) % 2 == 0) {
	       mod[c[i]]++;
	   }
	}
	int mx = 0;
	for (int i = 0; i < 2*n; i++) {
	   mx = max(mod[i], mx);
	}
	if (gd) {
	    cout << n - 1 << "\n";
	    deque <int> xx, yy, zz;
        for (int i = 1; i < n; i++) {
            xx.push_back(i);
        }
        for (int i = 0; i + 3 < 2 * n; i++) {
            if ((i + 3) % 2 != 0) {
                yy.push_back(i + 3);
                zz.push_back(i + 3);
            }
        }
        vector <int> x, y, z;
        for (int i = 1; i < n; i++) {
            if (i % 2 == 1) {
                int k = xx.front();
                xx.pop_front();
                x.push_back(k);
                
                int t = yy.front();
                yy.pop_front();
                y.push_back(t);
                
                int c = zz.back();
                zz.pop_back();
                z.push_back(c);
                
            } else {
                int k = xx.back();
                xx.pop_back();
                x.push_back(k);
                
                int t = yy.back();
                yy.pop_back();
                y.push_back(t);
                
                int c = zz.front();
                zz.pop_front();
                z.push_back(c);
            }
            
        }
    	for (int i = 0; i < n - 1; i++) {
    	    cout << x[i] << " "  << y[i] << " " << z[i] << "\n";
    	}
	} else {
	    cout << n - mx << "\n";
	}
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...