답안 #26118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26118 2017-06-28T05:04:11 Z 시제연(#1098) Memory 2 (JOI16_memory2) C++
0 / 100
2000 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;
    for (i=0;i<cand.size();i++) {
        for (j=i+1;j<cand.size();j++) {
            cnt[res[cand[i]][cand[j]]]++;
        }
    }
    int maxi=-1, t=-1;
    for (i=0;i<cand.size();i++) {
        for (j=i+1;j<cand.size();j++) {
            if (maxi<cnt[res[cand[i]][cand[j]]]) {
                maxi=cnt[res[cand[i]][cand[j]]];
                t = res[cand[i]][cand[j]];
            }
        }
    }
    vector<int> era;
    for (i=0;i<cand.size();i++) {
        bool flag = true;
        for (j=0;j<cand.size();j++) {
            if (i==j) continue;
            if (res[cand[i]][cand[j]]!=t) flag = false;
        }
        if (flag) {
            ans[cand[i]] = t;
            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:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<cand.size();i++) {
               ^
memory2.cpp:21:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=i+1;j<cand.size();j++) {
                     ^
memory2.cpp:26:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<cand.size();i++) {
               ^
memory2.cpp:27:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=i+1;j<cand.size();j++) {
                     ^
memory2.cpp:35:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<cand.size();i++) {
               ^
memory2.cpp:37:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<cand.size();j++) {
                   ^
memory2.cpp:46: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:63:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<cand.size();j++) {
                   ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2000 ms 2072 KB Execution timed out
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2000 ms 2072 KB Execution timed out
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2000 ms 2072 KB Execution timed out
2 Halted 0 ms 0 KB -