Submission #83399

# Submission time Handle Problem Language Result Execution time Memory
83399 2018-11-07T13:43:29 Z Tusk Teleporters (IOI08_teleporters) C++14
85 / 100
635 ms 66560 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e6+1;

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;
            int u = i;
            while(1) {
                  ++sz[comp];
                  int v = dp[mp[pos[u]]];
                  if(chk[v] || v == 2*n) break;
                  chk[v] = true;
                  u = 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:13: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:15: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 14 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8676 KB Output is correct
2 Correct 19 ms 8944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8944 KB Output is correct
2 Correct 19 ms 9392 KB Output is correct
3 Correct 23 ms 9752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 14648 KB Output is correct
2 Correct 232 ms 24884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 25508 KB Output is correct
2 Correct 368 ms 37092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 406 ms 48668 KB Output is correct
2 Correct 466 ms 60916 KB Output is correct
3 Runtime error 405 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.
# Verdict Execution time Memory Grader output
1 Runtime error 606 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.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 635 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.
2 Halted 0 ms 0 KB -