답안 #701843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701843 2023-02-22T07:32:37 Z minhcool Shopping (JOI21_shopping) C++17
10 / 100
475 ms 274428 KB
#include "Anna.h"
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 1e6 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

int nn, l, r;

void InitA(int N, int L, int R){
	nn = N, l = L, r = R;
	l++, r++;
}

int cnt1 = 0, cnt2 = 0;

vector<int> lst_bits;

ii ans = {oo, oo};

void ReceiveA(bool x){
	cnt1++;
	lst_bits.pb(x);
	//cout << cnt1 << "\n";
	if(nn > 10){
		if(cnt1 % 40) return;
		if(cnt2 < 18){
			int le = 0, ri = 0;
			for(int i = 0; i < 20; i++) le = (le * 2 + lst_bits[i]);
			for(int i = 0; i < 20; i++) ri = (ri * 2 + lst_bits[i + 20]);
			if(le <= l && ri >= r) SendA(1);
			else SendA(0);
			lst_bits.clear();
			cnt2++;
		}
		else{
			int pos = 0, val = 0;
			for(int i = 0; i < 20; i++) pos = (pos * 2 + lst_bits[i]);
			for(int i = 0; i < 20; i++) val = (val * 2 + lst_bits[i + 20]);
			if(l <= pos && pos <= r) ans = min(ans, {val, pos});
			lst_bits.clear();
		}
	}
	else{
		if(cnt1 % 20) return;
		int pos = (cnt1 / 20), val = 0;
		for(int i = 0; i < 20; i++) val = (val * 2 + lst_bits[i]);
		//cout << pos << " " << val << "\n";
		if(l <= pos && pos <= r) ans = min(ans, {val, pos});
		lst_bits.clear();
	}
}

int Answer(){
	//cout << ans.fi << " " << ans.se << "\n";
	return ans.se - 1;
}
#include "Bruno.h"
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1e6 + 5;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, arr[N];
int mini[N][21];
 
int mn_pos(int l, int r){
	int k = log2(r - l + 1);
	if(arr[mini[l][k]] < arr[mini[r - (1LL << k) + 1][k]]) return mini[l][k];
	else return mini[r - (1LL << k) + 1][k];
}
 
int cnt, par[N];
 
set<int> childs[N];
ii ranges[N];
 
int pos[N];
 
void build(int l, int r, int pare){
	if(l > r) return;
	int temp = mn_pos(l, r);
	cnt++;
	pos[cnt] = temp;
	if(pare){
		//cout << cnt << " " << pare << " " << l << " " << r << "\n";
		childs[pare].insert(cnt);
		par[cnt] = pare;
	}
	ranges[cnt] = {l, r};
	int tempo = cnt;
	build(l, temp - 1, tempo);
	build(temp + 1, r, tempo);
}
 
int cur_root, cur_ask;
 
int sz[N];
 
void prep(int u){
	sz[u] = 1;
	for(auto v : childs[u]){
		prep(v);
		sz[u] += sz[v];
	}
}
 
void sendnum(int x){
	//cout << x << "\n";
	for(int i = 19; i >= 0; i--){
		SendB((x & (1LL << i)) != 0);
	}
}
 
void InitB(int nn, vector<int> P){
	n = nn;
	///P.push_front(0);
	vector<int> P2;
	P2.pb(0);
	for(auto it : P) P2.pb(it);
	P = P2;
	for(int i = 1; i <= n; i++) arr[i] = P[i];
	for(int i = 1; i <= n; i++) mini[i][0] = i;
	for(int i = 1; i <= 19; i++){
		for(int j = 1; (j + (1LL << i) - 1) <= n; j++){
			int temp1 = P[mini[j][i - 1]], temp2 = P[mini[j + (1LL << (i - 1))][i - 1]];
			if(temp1 < temp2) mini[j][i] = mini[j][i - 1];
			else mini[j][i] = mini[j + (1LL << (i - 1))][i - 1];
		}
	}
	build(1, n, 0);
	if(n > 10){
		cur_root = 1;
		for(int i = 1; i <= n; i++) sz[i] = 0;
		prep(cur_root);
		ii mn = {oo, oo};
		for(int i = 1; i <= n; i++) mn = min(mn, {abs(sz[i] - n/2), i});
		cur_ask = mn.se;
		//cout << cur_ask << " " << ranges[cur_ask].fi << " " << ranges[cur_ask].se << "\n";
		sendnum(ranges[mn.se].fi), sendnum(ranges[mn.se].se);
		/*
		cur_root = 1, cur_ask = find_cen(1);
		ii mx = {-1, -1};
		for(auto v : child[cur_ask]) mx = max(mx, {sz[v], v});
		cur_ask = v.se;
		sendnum(range[cur_ask].fi);
		sendnum(range[cur_ask].se);*/
		//for(int i = 0; i <= 19; i++) SendB()
	}
	else{
		//cout << "OK\n" << n << "\n";
		for(int i = 1; i <= n; i++) sendnum(P[i]);
	}
}
 
int c = 0;
 
void prep2(int u){
	sendnum(pos[u]);
	sendnum(arr[pos[u]]);
	for(auto v : childs[u]) prep2(v);
}
 
void ReceiveB(bool y) {
	assert(n > 10);
	c++;
	if(!y) childs[par[cur_ask]].erase(cur_ask);
	else cur_root = cur_ask;
	//cout << cur_root << "\n";
	if(c < 18){
		for(int i = 1; i <= n; i++) sz[i] = 0;
		prep(cur_root);
		ii mn = {oo, oo};
		for(int i = 1; i <= n; i++) if(sz[i] != 0) mn = min(mn, {abs(sz[i] - sz[cur_root]/2), i});
		//for(int i = 1; i <= n; i++) cout << i << " " << sz[i] << "\n";
		cur_ask = mn.se;
		//cout << sz[cur_ask] << "\n";
		//cout << cur_ask << "\n";
		//cout << ranges[cur_ask].fi << " " << ranges[cur_ask].se << "\n";
		sendnum(ranges[mn.se].fi), sendnum(ranges[mn.se].se);
	}
	else{
		prep(cur_root);
		//cout << sz[cur_root] << "\n";
		prep2(cur_root);
	}
}
 
/*
20 9 16
5 7 10 8 6 3 2 1 9 4 12 15 18 20 19 17 14 13 16 11
*/

Compilation message

Anna.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~

Bruno.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47488 KB Output is correct
2 Correct 25 ms 47388 KB Output is correct
3 Correct 23 ms 47484 KB Output is correct
4 Correct 24 ms 47368 KB Output is correct
5 Correct 24 ms 47448 KB Output is correct
6 Correct 27 ms 47560 KB Output is correct
7 Correct 24 ms 47596 KB Output is correct
8 Correct 31 ms 47568 KB Output is correct
9 Correct 30 ms 47604 KB Output is correct
10 Correct 28 ms 47568 KB Output is correct
11 Correct 33 ms 47596 KB Output is correct
12 Correct 30 ms 47696 KB Output is correct
13 Correct 30 ms 47660 KB Output is correct
14 Correct 30 ms 47632 KB Output is correct
15 Correct 28 ms 47608 KB Output is correct
16 Correct 27 ms 47564 KB Output is correct
17 Correct 31 ms 47612 KB Output is correct
18 Correct 30 ms 47556 KB Output is correct
19 Correct 27 ms 47632 KB Output is correct
20 Correct 30 ms 47632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47488 KB Output is correct
2 Correct 25 ms 47388 KB Output is correct
3 Correct 23 ms 47484 KB Output is correct
4 Correct 24 ms 47368 KB Output is correct
5 Correct 24 ms 47448 KB Output is correct
6 Correct 27 ms 47560 KB Output is correct
7 Correct 24 ms 47596 KB Output is correct
8 Correct 31 ms 47568 KB Output is correct
9 Correct 30 ms 47604 KB Output is correct
10 Correct 28 ms 47568 KB Output is correct
11 Correct 33 ms 47596 KB Output is correct
12 Correct 30 ms 47696 KB Output is correct
13 Correct 30 ms 47660 KB Output is correct
14 Correct 30 ms 47632 KB Output is correct
15 Correct 28 ms 47608 KB Output is correct
16 Correct 27 ms 47564 KB Output is correct
17 Correct 31 ms 47612 KB Output is correct
18 Correct 30 ms 47556 KB Output is correct
19 Correct 27 ms 47632 KB Output is correct
20 Correct 30 ms 47632 KB Output is correct
21 Correct 33 ms 49056 KB Output is correct
22 Correct 37 ms 49052 KB Output is correct
23 Correct 35 ms 49040 KB Output is correct
24 Correct 29 ms 49040 KB Output is correct
25 Correct 30 ms 49040 KB Output is correct
26 Correct 34 ms 49176 KB Output is correct
27 Correct 32 ms 49560 KB Output is correct
28 Correct 30 ms 49768 KB Output is correct
29 Correct 33 ms 49368 KB Output is correct
30 Correct 34 ms 49164 KB Output is correct
31 Correct 32 ms 49044 KB Output is correct
32 Correct 30 ms 49052 KB Output is correct
33 Correct 33 ms 49120 KB Output is correct
34 Correct 33 ms 49192 KB Output is correct
35 Correct 30 ms 49040 KB Output is correct
36 Correct 34 ms 49068 KB Output is correct
37 Correct 30 ms 49032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 440 ms 209852 KB Output is correct
2 Correct 412 ms 211752 KB Output is correct
3 Correct 413 ms 211828 KB Output is correct
4 Correct 428 ms 211716 KB Output is correct
5 Correct 444 ms 258852 KB Output is correct
6 Memory limit exceeded 475 ms 274428 KB
7 Halted 0 ms 0 KB -