# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
828369 |
2023-08-17T08:58:15 Z |
박상훈(#10381) |
Toxic Gene (NOI23_toxic) |
C++17 |
|
12 ms |
468 KB |
#include "toxic.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 seed(1557);
int I[303], mem;
vector<char> typ;
pair<vector<int>, vector<int>> query_exp(const vector<int> &V, const vector<int> &W){
vector<int> Q;
for (int i=0;i<(int)V.size();i++){
for (int j=0;j<(1<<i);j++) Q.push_back(V[i]);
}
for (int i=0;i<(int)W.size();i++) Q.push_back(W[i]);
for (auto &x:Q) x = I[x];
int ret = query_sample(Q);
mem = (int)Q.size() - ret;
vector<int> dead, alive;
for (int i=0;i<(int)V.size();i++){
if (ret&(1<<i)) alive.push_back(V[i]);
else dead.push_back(V[i]);
}
return {dead, alive};
}
int query_linear(const vector<int> &V){
vector<int> Q;
for (auto &x:V) Q.push_back(I[x]);
return query_sample(Q);
}
int search(const vector<int> &dead, vector<pair<int, int>> &P){
int l = 0, r = (int)dead.size()-1;
while(l<r){
int m = (l+r)>>1;
vector<int> V, fuck;
for (int i=l;i<=m;i++) V.push_back(dead[i]);
if (!P.empty()){
auto [l2, r2] = P.back();
for (int i=l2;i<=r2;i++) fuck.push_back(i);
auto [deadF, aliveF] = query_exp(fuck, V);
if (mem==0) l = m+1;
else{
for (auto &x:deadF) typ[x] = 'R';
for (auto &x:aliveF) typ[x] = 'S';
P.pop_back();
r = m;
}
}
else{
if (query_linear(V)==(int)V.size()) l = m+1;
else r = m;
}
}
return dead[l];
}
vector<int> merge(vector<int> A, vector<int> B){
vector<int> C;
for (auto &x:A) C.push_back(x);
for (auto &x:B) C.push_back(x);
return C;
}
void determine_type(int n){
for (int i=1;i<=n;i++) I[i] = i;
shuffle(I+1, I+n+1, seed);
typ.clear();
typ.resize(n+1);
vector<int> toxic;
vector<pair<int, int>> P;
vector<vector<int>> que;
for (int i=1;i<=n;i+=8){
int r = min(n, i+7);
vector<int> V;
for (int j=i;j<=r;j++) V.push_back(j);
auto [dead, alive] = query_exp(V, vector<int>());
if (dead.empty()){P.emplace_back(i, r); continue;}
for (auto &x:alive) typ[x] = 'S';
que.push_back(dead);
continue;
// printf("dead: ");
// for (auto &x:dead) printf("%d ", x);
// printf("\n");
// printf("alive: ");
// for (auto &x:alive) printf("%d ", x);
// printf("\n");
// while(true){
// int p = search(dead, P);
// toxic.push_back(p);
// typ[p] = 'T';
// // printf("found toxic: %d\n", I[p]);
// dead.erase(find(dead.begin(), dead.end(), p));
// if (query_linear(dead)==(int)dead.size()) break;
// }
// for (auto &x:dead) typ[x] = 'R';
}
// while(que.size() >= 2){
// auto X = que.back(); que.pop_back();
// auto Y = que.back();
// for (auto &x:Y) X.push_back(x);
// // bool flag = find(X.begin(), X.end(), 240)!=X.end();
// // if (flag){
// // for (auto &x:X) printf(" %d", x);
// // printf("\n");
// // }
// int p = search(X, P);
// toxic.push_back(p);
// typ[p] = 'T';
// // printf("toxic found %d\n", I[p]);
// auto titer = find(X.begin(), X.end(), p);
// for (auto iter=X.begin();iter!=titer;iter++){
// typ[*iter] = 'R';
// }
// X.erase(X.begin(), next(titer));
// // if (flag){
// // for (auto &x:X) printf(" %d", x);
// // printf("\n");
// // }
// if (X.size() > Y.size()){
// for (int i=0;i<(int)Y.size();i++) X.pop_back();
// que.push_back(X);
// }
// else{
// que.pop_back();
// que.push_back(X);
// }
// }
// assert(que.size()==1);
for (auto &dead:que){
// if (query_linear(dead)==(int)dead.size()){
// for (auto &x:dead) typ[x] = 'R';
// continue;
// }
{
int p = search(dead, P);
toxic.push_back(p);
typ[p] = 'T';
auto titer = find(dead.begin(), dead.end(), p);
for (auto iter=dead.begin();iter!=titer;iter++){
typ[*iter] = 'R';
}
dead.erase(dead.begin(), next(titer));
// if (query_linear(dead)==(int)dead.size()) break;
}
// for (auto &x:dead) typ[x] = 'R';
}
while(true){
sort(que.begin(), que.end(), [](const vector<int> &a, const vector<int> &b){return a.size() > b.size();});
while(!que.empty() && que.back().empty()) que.pop_back();
if (que.empty()) break;
while(que.size()>=2){
if (que.back().size() + (*++que.rbegin()).size() > 8) break;
auto V = merge(que.back(), *++que.rbegin());
que.pop_back();
que.pop_back();
que.push_back(V);
sort(que.begin(), que.end(), [](const vector<int> &a, const vector<int> &b){return a.size() > b.size();});
}
for (auto &dead:que){
if (query_linear(dead)==(int)dead.size()){
for (auto &x:dead) typ[x] = 'R';
dead.clear();
continue;
}
{
int p = search(dead, P);
toxic.push_back(p);
typ[p] = 'T';
auto titer = find(dead.begin(), dead.end(), p);
for (auto iter=dead.begin();iter!=titer;iter++){
typ[*iter] = 'R';
}
dead.erase(dead.begin(), next(titer));
// if (query_linear(dead)==(int)dead.size()) break;
}
}
}
for (auto &[l, r]:P){
vector<int> V;
for (int j=l;j<=r;j++) V.push_back(j);
auto [dead, alive] = query_exp(V, vector<int>(1, toxic[0]));
for (auto &x:dead) typ[x] = 'R';
for (auto &x:alive) typ[x] = 'S';
}
for (int i=1;i<=n;i++) answer_type(I[i], typ[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
404 KB |
Output is correct |
3 |
Correct |
10 ms |
376 KB |
Output is correct |
4 |
Correct |
10 ms |
408 KB |
Output is correct |
5 |
Correct |
11 ms |
340 KB |
Output is correct |
6 |
Correct |
10 ms |
320 KB |
Output is correct |
7 |
Correct |
10 ms |
400 KB |
Output is correct |
8 |
Correct |
10 ms |
400 KB |
Output is correct |
9 |
Correct |
12 ms |
404 KB |
Output is correct |
10 |
Correct |
10 ms |
340 KB |
Output is correct |
11 |
Correct |
12 ms |
400 KB |
Output is correct |
12 |
Correct |
10 ms |
404 KB |
Output is correct |
13 |
Correct |
10 ms |
340 KB |
Output is correct |
14 |
Correct |
10 ms |
400 KB |
Output is correct |
15 |
Correct |
10 ms |
340 KB |
Output is correct |
16 |
Correct |
10 ms |
404 KB |
Output is correct |
17 |
Correct |
10 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
468 KB |
Output is correct |
19 |
Correct |
10 ms |
340 KB |
Output is correct |
20 |
Correct |
10 ms |
404 KB |
Output is correct |
21 |
Correct |
9 ms |
352 KB |
Output is correct |
22 |
Correct |
9 ms |
340 KB |
Output is correct |
23 |
Correct |
8 ms |
340 KB |
Output is correct |
24 |
Correct |
10 ms |
340 KB |
Output is correct |
25 |
Correct |
10 ms |
340 KB |
Output is correct |
26 |
Correct |
11 ms |
340 KB |
Output is correct |
27 |
Correct |
11 ms |
340 KB |
Output is correct |
28 |
Correct |
10 ms |
404 KB |
Output is correct |
29 |
Correct |
12 ms |
400 KB |
Output is correct |
30 |
Correct |
10 ms |
340 KB |
Output is correct |
31 |
Correct |
10 ms |
376 KB |
Output is correct |
32 |
Correct |
11 ms |
340 KB |
Output is correct |
33 |
Correct |
11 ms |
400 KB |
Output is correct |
34 |
Correct |
10 ms |
400 KB |
Output is correct |
35 |
Correct |
10 ms |
364 KB |
Output is correct |
36 |
Correct |
2 ms |
212 KB |
Output is correct |