답안 #56734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56734 2018-07-12T08:58:56 Z top34051 Memory 2 (JOI16_memory2) C++17
100 / 100
8 ms 4736 KB
#include "Memory2_lib.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e3 + 5;

int n;
int bad[maxn];
vector<int> pos[maxn];
int rec[maxn][maxn];

int ask(int x, int y) {
    if(x>y) swap(x,y);
    if(rec[x][y]!=-1) return rec[x][y];
    return rec[x][y] = Flip(x,y);
}

int solve(int x) {
    for(int i=0;i<n;i++) pos[i].clear();
    for(int i=0;i<2*n;i++) {
        if(i!=x) pos[ask(i,x)].push_back(i);//, printf("%d : %d\n",i,ask(i,x));
    }
    int cnt = 0;
    for(int i=0;i<n;i++) {
        if(pos[i].size()==1) pos[i].push_back(x), cnt++;
        if(pos[i].size()!=2) return 0;
    }
    if(cnt>1) return 0;
    for(int i=0;i<n;i++) Answer(pos[i][0],pos[i][1],i);
    return 1;
}

void Solve(int T, int N) {
    memset(rec,-1,sizeof(rec));
    n = N;
    int x = 0, noey = 0;
    while(1) {
//        printf("x = %d\n",x);
        int ok = 0;
        for(int y=x+1;y<2*n;y++) {
            if(bad[y]) continue;
            int tmp = ask(x,y);
//            printf("\ty = %d : %d\n",y,tmp);
            pos[tmp].push_back(y);
            if(pos[tmp].size()==3) {
                x = pos[tmp][0]; noey = pos[tmp][1];
                for(int i=0;i<n;i++) {
                    if(i==tmp) continue;
                    for(auto t : pos[i]) bad[t] = 1;
                }
                for(int i=0;i<n;i++) pos[i].clear();
                ok = 1;
                break;
            }
        }
        if(!ok) break;
    }
    if(solve(x)) return ;
    solve(noey);
    return ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4344 KB Output is correct
2 Correct 6 ms 4452 KB Output is correct
3 Correct 6 ms 4452 KB Output is correct
4 Correct 7 ms 4456 KB Output is correct
5 Correct 6 ms 4484 KB Output is correct
6 Correct 6 ms 4484 KB Output is correct
7 Correct 6 ms 4484 KB Output is correct
8 Correct 7 ms 4512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4512 KB Output is correct
2 Correct 5 ms 4584 KB Output is correct
3 Correct 6 ms 4584 KB Output is correct
4 Correct 7 ms 4588 KB Output is correct
5 Correct 7 ms 4588 KB Output is correct
6 Correct 7 ms 4588 KB Output is correct
7 Correct 8 ms 4624 KB Output is correct
8 Correct 6 ms 4652 KB Output is correct
9 Correct 6 ms 4696 KB Output is correct
10 Correct 7 ms 4696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4696 KB Output is correct
2 Correct 7 ms 4704 KB Output is correct
3 Correct 8 ms 4708 KB Output is correct
4 Correct 7 ms 4712 KB Output is correct
5 Correct 6 ms 4712 KB Output is correct
6 Correct 7 ms 4720 KB Output is correct
7 Correct 7 ms 4724 KB Output is correct
8 Correct 6 ms 4728 KB Output is correct
9 Correct 7 ms 4728 KB Output is correct
10 Correct 6 ms 4736 KB Output is correct