답안 #45462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45462 2018-04-14T08:39:01 Z Extazy 도서관 (JOI18_library) C++17
0 / 100
210 ms 912 KB
#include <bits/stdc++.h>
#include "library.h"
#ifdef skeleta
    #include "grader.cpp"
#endif

using namespace std;

const int MAXN = 1007;

int n;
vector < int > v[MAXN];
vector < pair < int, int > > p;
int questions_count;
bool used[MAXN];
queue < int > q;
vector < int > ans;

void Solve(int N) {
    int i,j;
    vector < int > qry;
    
    n=N;
    
    qry.assign(n,0);

    for(i=1;i<=n;i++) {
        for(j=i+1;j<=n;j++) {
            p.push_back(make_pair(i,j));
        }
    }

    random_shuffle(p.begin(),p.end());

    for(i=0;i<(int)(p.size()) && questions_count<20000;i++) {
        if(v[p[i].first].size()==2 || v[p[i].second].size()==2) continue;
        
        qry[p[i].first-1]=1;
        qry[p[i].second-1]=1;
       
        ++questions_count;

        if(Query(qry)==1) {
            v[p[i].first].push_back(p[i].second);
            v[p[i].second].push_back(p[i].first);
        }

        qry[p[i].first-1]=0;
        qry[p[i].second-1]=0;
    }

    for(i=1;i<=n;i++) if(v[i].size()==1) {
        used[i]=true;
        q.push(i);
        break;
    }

    while(!q.empty()) {
        int curr=q.front();
        q.pop();
        
        ans.push_back(curr);

        for(i=0;i<(int)(v[curr].size());i++) if(!used[v[curr][i]]) {
            used[v[curr][i]]=true;
            q.push(v[curr][i]);
        }
    }

    Answer(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 632 KB Output is correct
2 Correct 137 ms 824 KB Output is correct
3 Correct 185 ms 900 KB Output is correct
4 Correct 164 ms 900 KB Output is correct
5 Correct 183 ms 900 KB Output is correct
6 Correct 146 ms 900 KB Output is correct
7 Correct 210 ms 900 KB Output is correct
8 Correct 140 ms 912 KB Output is correct
9 Correct 150 ms 912 KB Output is correct
10 Correct 48 ms 912 KB Output is correct
11 Incorrect 2 ms 912 KB Wrong Answer [4]
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 632 KB Output is correct
2 Correct 137 ms 824 KB Output is correct
3 Correct 185 ms 900 KB Output is correct
4 Correct 164 ms 900 KB Output is correct
5 Correct 183 ms 900 KB Output is correct
6 Correct 146 ms 900 KB Output is correct
7 Correct 210 ms 900 KB Output is correct
8 Correct 140 ms 912 KB Output is correct
9 Correct 150 ms 912 KB Output is correct
10 Correct 48 ms 912 KB Output is correct
11 Incorrect 2 ms 912 KB Wrong Answer [4]
12 Halted 0 ms 0 KB -