Submission #80152

# Submission time Handle Problem Language Result Execution time Memory
80152 2018-10-19T08:02:56 Z Sherazin Teleporters (IOI08_teleporters) C++14
90 / 100
830 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+5;

int n, m;
bitset<N> chk;
int sz[N], mp[N], dp[N], pos[N], comp;
vector<int> V(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++) V[i-2] = sz[i];
      sort(V.begin(), V.end(), greater<int>());
      for(int i = 0; i < comp-1 && m; i++, m--) ans += V[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 59 ms 15992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 16144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 16144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 16144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 16144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 16212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 16212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 16264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 16264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 16264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 16264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 16460 KB Output is correct
2 Correct 63 ms 16904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 16904 KB Output is correct
2 Correct 64 ms 17100 KB Output is correct
3 Correct 67 ms 17372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 17468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 17608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 20864 KB Output is correct
2 Correct 356 ms 26924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 245 ms 26924 KB Output is correct
2 Correct 502 ms 29512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 565 ms 32152 KB Output is correct
2 Correct 685 ms 44380 KB Output is correct
3 Correct 598 ms 56572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 817 ms 56680 KB Output is correct
2 Runtime error 828 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 -
# Verdict Execution time Memory Grader output
1 Runtime error 830 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 -