Submission #248353

# Submission time Handle Problem Language Result Execution time Memory
248353 2020-07-12T09:32:38 Z VEGAnn Sirni (COCI17_sirni) C++14
56 / 140
5000 ms 786436 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define PB push_back
#define i2 array<int,2>
using namespace std;
typedef long long ll;
const int N = 100100;
const int BIG = int(1e7) + 10;
const int cn = int(1e4);
const int oo = 2e9;
bool mrk[BIG];
vector<i2> edg;
vector<int> vc;
int n, nt[BIG];
ll ans = 0;

int get(int x) { return (x == nt[x] ? x : nt[x] = get(nt[x])); }

void calc(){
    for (int i = BIG - 2; i > 0; i--)
        if (mrk[i])
            nt[i] = i;
        else nt[i] = nt[i + 1];

    for (int cr : vc){
        int cm = mrk[cr];

        int x = cr;

        nt[get(x)] = get(x + 1);

        for (int i = get(x); i < BIG - 1; ){
            int nw = i % x;

            edg.PB({i, x});

            if (nw == 0)
                i += x;
            else i += x - nw;

            i = get(i);
        }
    }
}

bool cmp(i2 _x, i2 _y){
    return (_x[0] % _x[1]) < (_y[0] % _y[1]);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

    for (int i = 1; i <= n; i++){
        int x; cin >> x;
        mrk[x] = 1;
    }

    int siz = 0;

    for (int i = 1; i < BIG; i++)
        if (mrk[i]) {
            siz++;
            vc.PB(i);
        }

    nt[BIG - 1] = BIG - 1;

    calc();

    sort(all(edg), cmp);

    for (int cr : vc)
        nt[cr] = cr;

    for (i2 nw : edg){
        int x = get(nw[0]), y = get(nw[1]);

        if (x == y) continue;

        ans += nw[0] % nw[1];

        nt[x] = y;
    }

    cout << ans << '\n';

    return 0;
}

Compilation message

sirni.cpp: In function 'void calc()':
sirni.cpp:27:13: warning: unused variable 'cm' [-Wunused-variable]
         int cm = mrk[cr];
             ^~
# Verdict Execution time Memory Grader output
1 Runtime error 1590 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 39672 KB Output is correct
2 Runtime error 1481 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2293 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 416 ms 49252 KB Output is correct
2 Correct 1457 ms 73816 KB Output is correct
3 Correct 573 ms 57468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 42732 KB Output is correct
2 Correct 849 ms 73576 KB Output is correct
3 Correct 412 ms 48616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 849 ms 73796 KB Output is correct
2 Correct 1831 ms 106652 KB Output is correct
3 Correct 518 ms 57436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 44136 KB Output is correct
2 Correct 1747 ms 106576 KB Output is correct
3 Correct 501 ms 57312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5104 ms 600372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3804 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1764 ms 786436 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -