답안 #785395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785395 2023-07-17T08:52:00 Z bachhoangxuan Memory 2 (JOI16_memory2) C++17
100 / 100
1 ms 340 KB
#include "Memory2_lib.h"
#include<bits/stdc++.h>
using namespace std;

void Solve(int T, int N){
    vector<int> p(2*N,-1),cnt(N,0);
    vector<vector<int>> res(2*N,vector<int>(2*N,-1));
    auto query = [&](int i,int j){
        if(res[i][j]!=-1) return res[i][j];
        return res[i][j]=res[j][i]=Flip(i,j);
    };
    vector<int> cur={0,1};
    auto change = [&](){
        for(int x:cur){
            for(int y:cur){
                if(x==y) continue;
                for(int z:cur){
                    if(z==x || z==y) continue;
                    int a=query(x,y),b=query(x,z),c=query(y,z);
                    if(a==b && a!=c) p[x]=a;
                }
            }
        }
        vector<int> nw;
        for(int x:cur) if(p[x]==-1) nw.push_back(x);
        cur=nw;
    };
    for(int i=2;i<2*N;i++) cur.push_back(i),change();
    for(int i=0;i<2*N;i++) if(p[i]!=-1) cnt[p[i]]++;
    for(int i=0;i<N;i++) if(cnt[p[i]]!=2) cur.push_back(i);
    cnt.assign(N,0);change();
    int num=0;
    for(int i=0;i<2*N;i++) if(p[i]!=-1) cnt[p[i]]++;
    while(cnt[num]==2) num++;
    for(int i=0;i<2*N;i++) if(p[i]==-1) p[i]=num;
    vector<vector<int>> ans(N);
    for(int i=0;i<2*N;i++) ans[p[i]].push_back(i);
    for(int i=0;i<N;i++) Answer(ans[i][0],ans[i][1],i);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct