Submission #80153

# Submission time Handle Problem Language Result Execution time Memory
80153 2018-10-19T08:10:34 Z Sherazin Teleporters (IOI08_teleporters) C++14
95 / 100
706 ms 66560 KB
#include <bits/stdc++.h>

#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 2e6+2;

int n, m;
bitset<N> chk;
int sz[N], mp[N], pos[N], comp;
vector<int> dp(N);

int main() {
      scanf("%d %d", &n, &m);
      for(int i = 1, a, b; i <= n; i++) {
            scanf("%d %d", &a, &b);
            mp[a] = b, mp[b] = a;
            ++dp[a], ++dp[b];
      }
      int ptr = 0;
      for(int i = 1; i < N; i++) {
            dp[i] += dp[i-1];
            if(dp[i] != dp[i-1]) pos[ptr++] = i;
      }
      for(int i = 0; i < 2*n; i++) if(!chk[i]) {
            ++comp;
            chk[i] = true;
            queue<int> Q;
            Q.emplace(i);
            while(!Q.empty()) {
                  int u = Q.front();
                  Q.pop();
                  ++sz[comp];
                  int v = dp[mp[pos[u]]];
                  if(chk[v] || v == 2*n) continue;
                  chk[v] = true;
                  Q.emplace(v);
            }
      }
      int ans = sz[1];
      for(int i = 2; i <= comp; i++) dp[i-2] = sz[i];
      sort(dp.begin(), dp.begin()+comp-1, greater<int>());
      for(int i = 0; i < comp-1 && m; i++, m--) ans += dp[i] + 2;
      if(m) ans += 2*(m - (m & 1)) + (m & 1);
      printf("%d\n", ans);

      return 0;
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:17:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &n, &m);
       ~~~~~^~~~~~~~~~~~~~~~~
teleporters.cpp:19:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8528 KB Output is correct
2 Correct 18 ms 8816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8816 KB Output is correct
2 Correct 20 ms 9260 KB Output is correct
3 Correct 24 ms 9660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 12960 KB Output is correct
2 Correct 234 ms 19172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 19172 KB Output is correct
2 Correct 376 ms 21860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 420 ms 24420 KB Output is correct
2 Correct 516 ms 30348 KB Output is correct
3 Correct 508 ms 30892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 674 ms 30936 KB Output is correct
2 Correct 675 ms 32116 KB Output is correct
3 Correct 507 ms 44824 KB Output is correct
4 Correct 486 ms 59496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 684 ms 61912 KB Output is correct
2 Runtime error 706 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
3 Halted 0 ms 0 KB -