Submission #1041558

# Submission time Handle Problem Language Result Execution time Memory
1041558 2024-08-02T05:46:19 Z 정민찬(#11002) Brought Down the Grading Server? (CEOI23_balance) C++17
0 / 100
37 ms 37188 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

vector<pair<ll,ll>> adj[200010];
int cnt[200010];
int num[200010];
int ori[200010];
int vis[200010];

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    ll N, S, T;
    cin >> N >> S >> T;
    vector<vector<ll>> a(N, vector<ll>(S));
    for (ll i=0; i<N; i++) {
        for (ll j=0; j<S; j++) {
            cin >> a[i][j];
        }
    }
    for (ll i=1; i<=T; i++) num[i] = i, ori[i] = i;
    int pv = T;
    for (ll i=0; i<N; i++) {
        vector<ll> node(S);
        for (ll j=0; j<S; j++) {
            if (cnt[num[a[i][j]]] == 2) {
                num[a[i][j]] = ++ pv;
                ori[num[a[i][j]]] = a[i][j];
            }
            cnt[num[a[i][j]]] ++;
            node[j] = num[a[i][j]];
        }
        adj[node[0]].push_back({node[1], i});
        adj[node[1]].push_back({node[0], i});
    }
    ll ppv = pv;
    for (ll i=1; i<=ppv; i++) {
        if (cnt[i] == 1) {
            if (cnt[pv] == 2) pv ++;
            adj[pv].push_back({i, -1});
            adj[i].push_back({pv, -1});
            cnt[pv] ++;
        }
    }
    //assert(cnt[pv] == 2);
    for (ll i=1; i<=pv; i++) {
        if (vis[i]) continue;
        int p = -1;
        int x = i;
        vector<int> vtx, edg;
        while (true) {
            vtx.push_back(x);
            vis[x] = 1;
            if (adj[x][0].first == p) swap(adj[x][0], adj[x][1]);
            edg.push_back(adj[x][0].second);
            p = x;
            x = adj[x][0].first;
            if (x == i) break;
        }
        for (ll j=0; j<vtx.size(); j++) {
            if (edg[j] == -1) continue;
            if (a[edg[j]][0] != ori[vtx[j]]) {
                swap(a[edg[j]][0], a[edg[j]][1]);
            }
        }
    }
    for (ll i=0; i<N; i++) {
        for (ll j=0; j<S; j++) {
            cout << a[i][j] << ' ';
        }
        cout << '\n';
    }

}

Compilation message

balance.cpp: In function 'int main()':
balance.cpp:61:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (ll j=0; j<vtx.size(); j++) {
      |                      ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Correct
2 Runtime error 5 ms 15964 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8028 KB Correct
2 Runtime error 5 ms 15968 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 37 ms 37188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 37 ms 37188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8028 KB Correct
2 Runtime error 5 ms 15968 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 15964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 15964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 15964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 37 ms 37188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 37 ms 37188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Correct
2 Runtime error 5 ms 15964 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -