답안 #26120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26120 2017-06-28T05:10:28 Z 시제연(#1098) Memory 2 (JOI16_memory2) C++
100 / 100
0 ms 2072 KB
#include "Memory2_lib.h"
#include <bits/stdc++.h>

using namespace std;

int n;
int res[110][110];
int cnt[110];
int ans[110];

void four(vector<int> &cand) {
    int i, j;
    for (i=0;i<cand.size();i++) {
        for (j=i+1;j<cand.size();j++) {
            if (~res[cand[i]][cand[j]]) continue;
            res[cand[i]][cand[j]] = res[cand[j]][cand[i]] = Flip(cand[i],cand[j]);
        }
    }
    for (i=0;i<n;i++) cnt[i] = 0;
    vector<int> era;
    for (i=0;i<cand.size();i++) {
        bool flag = true;
        int p = -1;
        for (j=0;j<cand.size();j++) {
            if (i==j) continue;
            if (~p) {
                if (res[cand[i]][cand[j]]!=p) flag = false;
            }
            else p = res[cand[i]][cand[j]];
        }
        if (flag) {
            ans[cand[i]] = p;
            era.push_back(i);
        }
    }
    for (i=0;i<era.size();i++) cand[era[i]] = -1;
}

void Solve(int T, int N) {
    if (N==1) {
        Answer(0,1,0);
        return;
    }
    n = N;
    memset(res,-1,sizeof(res));
    memset(ans,-1,sizeof(ans));
    int i, j;
    vector<int> cand;
    for (i=0;i<3;i++) cand.push_back(i);
    for (i=0;i<3;i++) for (j=i+1;j<3;j++) res[i][j] = res[j][i] = Flip(i,j);
    i = 3;
    while(cand.size()>=3) {
        for (j=0;j<cand.size();j++) {
            if (cand[j]==-1) cand.erase(cand.begin()+j--);
        }
        while(i<2*n&&cand.size()<4) cand.push_back(i++);
        four(cand);
    }
    ans[cand[0]] = ans[cand[1]] = n-1;
    for (i=0;i<n;i++) {
        int a = -1, b = -1;
        for (j=0;j<2*n;j++) {
            if (ans[j]==i) {
                if (~a) b = j;
                else a = j;
            }
        }
        Answer(a,b,i);
    }

	return;
}

Compilation message

memory2.cpp: In function 'void four(std::vector<int>&)':
memory2.cpp:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<cand.size();i++) {
               ^
memory2.cpp:14:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=i+1;j<cand.size();j++) {
                     ^
memory2.cpp:21:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<cand.size();i++) {
               ^
memory2.cpp:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<cand.size();j++) {
                   ^
memory2.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<era.size();i++) cand[era[i]] = -1;
               ^
memory2.cpp: In function 'void Solve(int, int)':
memory2.cpp:53:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<cand.size();j++) {
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2072 KB Output is correct
2 Correct 0 ms 2072 KB Output is correct
3 Correct 0 ms 2072 KB Output is correct
4 Correct 0 ms 2072 KB Output is correct
5 Correct 0 ms 2072 KB Output is correct
6 Correct 0 ms 2072 KB Output is correct
7 Correct 0 ms 2072 KB Output is correct
8 Correct 0 ms 2072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2072 KB Output is correct
2 Correct 0 ms 2072 KB Output is correct
3 Correct 0 ms 2072 KB Output is correct
4 Correct 0 ms 2072 KB Output is correct
5 Correct 0 ms 2072 KB Output is correct
6 Correct 0 ms 2072 KB Output is correct
7 Correct 0 ms 2072 KB Output is correct
8 Correct 0 ms 2072 KB Output is correct
9 Correct 0 ms 2072 KB Output is correct
10 Correct 0 ms 2072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2072 KB Output is correct
2 Correct 0 ms 2072 KB Output is correct
3 Correct 0 ms 2072 KB Output is correct
4 Correct 0 ms 2072 KB Output is correct
5 Correct 0 ms 2072 KB Output is correct
6 Correct 0 ms 2072 KB Output is correct
7 Correct 0 ms 2072 KB Output is correct
8 Correct 0 ms 2072 KB Output is correct
9 Correct 0 ms 2072 KB Output is correct
10 Correct 0 ms 2072 KB Output is correct