Submission #234741

# Submission time Handle Problem Language Result Execution time Memory
234741 2020-05-25T12:41:55 Z anayk None (JOI16_memory2) C++14
100 / 100
5 ms 384 KB
#include "Memory2_lib.h"
#include <vector>

void Solve(int T, int N){
  std::vector<int> ans(2*N, -1);

  int x = 0, y = 1, z = -1;
  int lastComp = Flip(x, y);

  for(int i = 2; i < 2*N; i++) {
    int xComp = Flip(i, x);
    int yComp = Flip(i, y);

    if(z == -1) {
      if(xComp == lastComp && yComp != lastComp) {
        ans[x] = lastComp;
        lastComp = yComp;
        x = i;
      }
      else if(yComp == lastComp && xComp != lastComp) {
        ans[y] = lastComp;
        lastComp = xComp;
        y = i;
      }
      else if(xComp == lastComp && yComp == lastComp) {
        z = i;
      }
      else {
        ans[i] = xComp;
      }
    }
    else {
      if(xComp == lastComp && yComp == lastComp) {
        ans[x] = ans[y] = lastComp;
        x = z;
        y = i;
        z = -1;
        lastComp = Flip(x, y);
      }
      else if(xComp == lastComp && yComp != lastComp) {
        ans[x] = ans[z] = lastComp;
        x = i;
        z = -1;
        lastComp = yComp;
      }
      else if(xComp != lastComp && yComp == lastComp) {
        ans[y] = ans[z] = lastComp;
        y = i;
        z = -1;
        lastComp = xComp;
      }
      else {
        ans[i] = xComp;
      }
    }
  }

  ans[x] = ans[y] = lastComp;

  std::vector<std::vector<int> > output(N);
  for(int i = 0; i < 2*N; i++) {
    output[ans[i]].push_back(i);
  }

  for(int i = 0; i < N; i++)
    Answer(output[i][0], output[i][1], i);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct