답안 #45464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45464 2018-04-14T08:40:28 Z Extazy 도서관 (JOI18_library) C++17
0 / 100
165 ms 1012 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;

    for(i=1;i<=n;i++) {
        used[i]=false;
        v[i].clear();
    }
    ans.clear();
    questions_count=0;
    p.clear();

    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 165 ms 676 KB Output is correct
2 Correct 132 ms 696 KB Output is correct
3 Correct 154 ms 772 KB Output is correct
4 Correct 162 ms 796 KB Output is correct
5 Correct 155 ms 796 KB Output is correct
6 Correct 147 ms 840 KB Output is correct
7 Correct 141 ms 888 KB Output is correct
8 Correct 152 ms 1012 KB Output is correct
9 Correct 159 ms 1012 KB Output is correct
10 Correct 66 ms 1012 KB Output is correct
11 Incorrect 2 ms 1012 KB Wrong Answer [4]
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 676 KB Output is correct
2 Correct 132 ms 696 KB Output is correct
3 Correct 154 ms 772 KB Output is correct
4 Correct 162 ms 796 KB Output is correct
5 Correct 155 ms 796 KB Output is correct
6 Correct 147 ms 840 KB Output is correct
7 Correct 141 ms 888 KB Output is correct
8 Correct 152 ms 1012 KB Output is correct
9 Correct 159 ms 1012 KB Output is correct
10 Correct 66 ms 1012 KB Output is correct
11 Incorrect 2 ms 1012 KB Wrong Answer [4]
12 Halted 0 ms 0 KB -