제출 #649611

#제출 시각아이디문제언어결과실행 시간메모리
649611PoonYaPat도서관 (JOI18_library)C++14
100 / 100
1010 ms57720 KiB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;

map<vector<int> ,int> have;

int query(vector<int> x) {
    bool check=false;
    for (int i=0; i<x.size(); ++i) if (x[i]) check=true;
    if (!check) return -1;
    else {
        if (!have[x]) have[x]=Query(x);
        return have[x];
    }
}

void Solve(int n) {
	int now=-1,pre=-1,ed;
	vector<int> test,ans;
	if (n==1) {
        ans.push_back(1);
        Answer(ans);
        return ;
	}
	for (int i=0; i<n; ++i) test.push_back(1);
	for (int i=0; i<n; ++i) {
        test[i]=0;
        if (query(test)==1) {
            if (now==-1) now=i;
            else ed=i;
        }
        test[i]=1;
	}
	ans.push_back(now+1);
	for (int i=0; i<n-1; ++i) {
        int l=0, r=n-1;
        while (l<r) {
            int mid=(l+r)/2;
            for (int i=0; i<n; ++i) {
                if (i==pre) test[i]=0;
                else if (i>=mid+1 && i<=r) test[i]=1;
                else test[i]=0;
            }
            int k1=query(test);
            test[now]=1-test[now];
            int k2=query(test);

            if (k1==k2) l=mid+1;
            else r=mid;
        }
        ans.push_back(r+1);
        pre=now; now=r;
	}
	Answer(ans);
}

컴파일 시 표준 에러 (stderr) 메시지

library.cpp: In function 'int query(std::vector<int>)':
library.cpp:9:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i=0; i<x.size(); ++i) if (x[i]) check=true;
      |                   ~^~~~~~~~~
library.cpp: In function 'void Solve(int)':
library.cpp:18:20: warning: variable 'ed' set but not used [-Wunused-but-set-variable]
   18 |  int now=-1,pre=-1,ed;
      |                    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...