Submission #1099787

# Submission time Handle Problem Language Result Execution time Memory
1099787 2024-10-12T05:17:42 Z gyg Brought Down the Grading Server? (CEOI23_balance) C++17
0 / 100
2000 ms 4436 KB
#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 time Memory Grader output
1 Correct 0 ms 2396 KB Correct
2 Runtime error 1 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Correct
2 Correct 0 ms 2396 KB Correct
3 Execution timed out 2067 ms 2396 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2045 ms 4436 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2045 ms 4436 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Correct
2 Correct 0 ms 2396 KB Correct
3 Execution timed out 2067 ms 2396 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2045 ms 4436 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2045 ms 4436 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Correct
2 Runtime error 1 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -