Submission #126461

# Submission time Handle Problem Language Result Execution time Memory
126461 2019-07-07T19:34:51 Z letrongdat Sirni (COCI17_sirni) C++17
0 / 140
614 ms 556012 KB
#include <bits/stdc++.h>
using namespace std;
#define forn(i, a, b)               for(int i=a; i<=b; ++i)
#define ford(i, a ,b)               for(int i=a; i>=b; --i)
#define repn(i, a, b)               for(int i=a; i <b; ++i)
typedef pair<int, int> ii;
const int maxM = 1e7+ 10;
const int maxN = 1e5 +10;
int N;
int Near[maxM];
int lab[maxN];
vector<int> P;
vector<ii> Edge[maxM];
int root(int u) {
    if (lab[u] < 0) return u;
    return lab[u] = root(lab[u]);
}
bool join(int u, int v) {
    int l1 = root(u), l2 = root(v);
    if (l1 == l2) return false;
    if (lab[l1] > lab[l2]) swap(l1, l2);
    lab[l1] += lab[l2];
    lab[l2] = l1;
    return true;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("a.inp", "r", stdin);
#endif // ONLINE_JUDGE
    ios::sync_with_stdio(0);
    memset(lab, -1, sizeof lab);
    cin >> N;
    P.resize(N);
    repn(i, 0, N) cin >> P[i];
    sort(P.begin(), P.end());
    P.resize(unique(P.begin(), P.end()) - P.begin());
    memset(Near, 0x3f, sizeof Near);
    repn(i, 0, P.size()) Near[P[i]] = i;
    ford(i, P.back(), 0) Near[i] = min(Near[i], Near[i+1]);
    repn(i, 0, P.size() -1) {
        int weight = P[Near[P[i]+1]] - P[i];
        Edge[weight].push_back({i, Near[P[i]+1]});
        for(int j = 2*P[i]; j <= P.back(); j += P[i]) {
            int weight = P[Near[j]] - j;
            if (weight >= P[i]) continue;
            Edge[weight].push_back({i, Near[j]});
        }
    }
    long long result = 0, cnt = 0;
    repn(i, 0, maxM) {
        if (cnt == P.size() -1) break;
        for(auto &e: Edge[i]) if (join(e.first, e.second)) {
            result += i;
            cnt ++;
        }
    }
    cout << result;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:5:52: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define repn(i, a, b)               for(int i=a; i <b; ++i)
sirni.cpp:38:10:
     repn(i, 0, P.size()) Near[P[i]] = i;
          ~~~~~~~~~~~~~~                             
sirni.cpp:38:5: note: in expansion of macro 'repn'
     repn(i, 0, P.size()) Near[P[i]] = i;
     ^~~~
sirni.cpp:5:52: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define repn(i, a, b)               for(int i=a; i <b; ++i)
sirni.cpp:40:10:
     repn(i, 0, P.size() -1) {
          ~~~~~~~~~~~~~~~~~                          
sirni.cpp:40:5: note: in expansion of macro 'repn'
     repn(i, 0, P.size() -1) {
     ^~~~
sirni.cpp:51:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (cnt == P.size() -1) break;
             ~~~~^~~~~~~~~~~~~~
sirni.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("a.inp", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 595 ms 555896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 595 ms 556012 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 599 ms 555804 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 590 ms 556012 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 594 ms 555908 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 614 ms 555956 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 596 ms 555880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 603 ms 555824 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 598 ms 555896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 608 ms 555996 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -