Submission #1099787

#TimeUsernameProblemLanguageResultExecution timeMemory
1099787gygBrought Down the Grading Server? (CEOI23_balance)C++17
0 / 100
2067 ms4436 KiB
#include <bits/stdc++.h> using namespace std; #define arr array #define pii pair<int, int> #define fir first #define sec second const int R = 1e5 + 5, C = 2 + 5, K = 1e5 + 5, INF = 1e9; int r, c, k; arr<arr<int, C>, R> vl; arr<int, K> blnc; void prcmp() { for (int i = 1; i <= r; i++) blnc[vl[i][1]]++, blnc[vl[i][2]]--; } void swp(int i) { blnc[vl[i][1]] -= 2, blnc[vl[i][2]] += 2; swap(vl[i][1], vl[i][2]); } void cmp() { while (true) { pii extrm = {-1, -1}; for (int i = 1; i <= k; i++) extrm = max(extrm, {abs(blnc[i]), i}); if (extrm.fir <= 1) break; int x = extrm.sec; if (blnc[x] > 0) { pii extrm2 = {INF, INF}; for (int i = 1; i <= r; i++) if (vl[i][1] == x) extrm2 = min(extrm2, {blnc[vl[i][2]], vl[i][2]}); for (int i = 1; i <= r; i++) if (vl[i][2] == extrm2.sec) { swp(i); break; } } else { pii extrm2 = {-1, -1}; for (int i = 1; i <= r; i++) if (vl[i][2] == x) extrm2 = max(extrm2, {blnc[vl[i][1]], vl[i][1]}); for (int i = 1; i <= r; i++) if (vl[i][1] == extrm2.sec) { swp(i); break; } } } } int main() { // freopen("bl.in", "r", stdin); cin >> r >> c >> k; assert(c == 2); for (int i = 1; i <= r; i++) for (int j = 1; j <= c; j++) cin >> vl[i][j]; prcmp(); cmp(); for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { cout << vl[i][j] << " "; } cout << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...