답안 #313175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313175 2020-10-15T12:06:54 Z vivaan_gupta 도서관 (JOI18_library) C++14
19 / 100
2000 ms 1404 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
 
using ll = long long;
using ld = long double;
using db = double; 
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>; 
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>; 
using vpd = vector<pd>;


// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define sor(x) sort(all(x)) 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)


vi x[1005];
bool done[1005][1005];
void Solve(int n){
	if(n == 1){
		vi a;
		a.pb(1);
		Answer(a);
		return;
	}
	vi a(n,-1);
	int ed = n-1;
	for(int i =0;i<n&&ed>0;i++){
		vi lol;
		for(int j =0;j<n&&ed>0;j++){
			if(j == i) continue;
			vi v(n,0);
			v[i] = 1;
			v[j] = 1;
			if(done[i][j]) continue;
			done[i][j]=true;
			done[j][i]=true;
			if(Query(v) == 1) lol.pb(j),ed--;;
		}
		trav(b,lol){x[i].pb(b);x[b].pb(i);}
	}
	int st=-1,en=-1;
	for(int i =0;i<n;i++){
		if(sz(x[i]) == 1){
			if(st == -1) st = i;
			else en = i;
		} 
	}
	set<int> vis;
	a[0] = st;
	vis.ins(st);
	for(int i =1;i<n;i++){
		for(auto j:x[a[i-1]]){
			if(vis.count(j) == 0){
				a[i] = j;
				vis.ins(j);
				break;
			}
		}
	}
	for(int i =0;i<n;i++) a[i] ++;
	Answer(a);
}
/* stuff you should look for
	* read the probem 3 more times in case of WA :)
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:77:12: warning: variable 'en' set but not used [-Wunused-but-set-variable]
   77 |  int st=-1,en=-1;
      |            ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 632 KB # of queries: 18311
2 Correct 260 ms 632 KB # of queries: 18135
3 Correct 283 ms 512 KB # of queries: 19573
4 Correct 274 ms 636 KB # of queries: 19673
5 Correct 309 ms 724 KB # of queries: 19886
6 Correct 293 ms 720 KB # of queries: 19863
7 Correct 308 ms 632 KB # of queries: 19783
8 Correct 249 ms 512 KB # of queries: 18486
9 Correct 270 ms 596 KB # of queries: 19682
10 Correct 110 ms 512 KB # of queries: 8194
11 Correct 0 ms 384 KB # of queries: 0
12 Correct 0 ms 384 KB # of queries: 1
13 Correct 0 ms 384 KB # of queries: 2
14 Correct 1 ms 384 KB # of queries: 5
15 Correct 3 ms 384 KB # of queries: 102
16 Correct 4 ms 384 KB # of queries: 324
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 632 KB # of queries: 18311
2 Correct 260 ms 632 KB # of queries: 18135
3 Correct 283 ms 512 KB # of queries: 19573
4 Correct 274 ms 636 KB # of queries: 19673
5 Correct 309 ms 724 KB # of queries: 19886
6 Correct 293 ms 720 KB # of queries: 19863
7 Correct 308 ms 632 KB # of queries: 19783
8 Correct 249 ms 512 KB # of queries: 18486
9 Correct 270 ms 596 KB # of queries: 19682
10 Correct 110 ms 512 KB # of queries: 8194
11 Correct 0 ms 384 KB # of queries: 0
12 Correct 0 ms 384 KB # of queries: 1
13 Correct 0 ms 384 KB # of queries: 2
14 Correct 1 ms 384 KB # of queries: 5
15 Correct 3 ms 384 KB # of queries: 102
16 Correct 4 ms 384 KB # of queries: 324
17 Execution timed out 3022 ms 1404 KB Time limit exceeded
18 Halted 0 ms 0 KB -