#include "doll.h"
#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef long long ll;
template<class T> bool umin(T& a, const T b){ if(a > b) { a = b; return true; } return false; }
template<class T> bool umax(T& a, const T b){ if(a < b) { a = b; return true; } return false; }
void create_circuit(int m, vector<int> a) {
int n = a.size();
vector<int> c(m + 1);
vector<int> cnt(m + 1);
a.insert(a.begin(), 0);
a.push_back(0);
for(int i=0;i<=n;i++){
cnt[a[i]]++;
}
vector<vector<int>> out(m + 1);
for(int i=1;i<=n+1;i++){
int x = a[i - 1], y = a[i];
//~ out[x].push_back(y);
out[x].push_back(y);
//~ if(cnt[y] == 1){
//~ out[x].push_back(y);
//~ } else {
//~ out[x].push_back(y);
//~ }
}
int last = 0;
vector<int> x_, y_;
auto get = [&](){
x_.push_back(0);
y_.push_back(0);
return ++last;
};
function<int(vector<int>&)> dfs = [&](vector<int>& a){
if((int)a.size() == 1){
return a[0];
}
//~ bool is_same = true;
vector<int> l, r;
for(int i=0;i<(int)a.size();i++){
if(i & 1) r.push_back(a[i]);
else l.push_back(a[i]);
//~ if(a[i] != a[0]) is_same = false;
}
//~ if(is_same){
//~ return a[0];
//~ }
int v = get();
if((int)a.size() & 1){
r.push_back(l.back());
l.back() = -v;
}
//~ cout<<"before: "<<dfs(l, 0)<<" "<<dfs(r, 0)<<endl;
int tmpLeft = dfs(l);
int tmpRight = dfs(r);
x_[v - 1] = tmpLeft;
y_[v - 1] = tmpRight;
//~ cout<<-v<<" "<<tmpLeft<<" "<<tmpRight<<"\n";
return -v;
};
for(int i=0;i<=m;i++){
if(!cnt[i]) continue;
if(cnt[i] == 1){
//~ cout<<i<<endl;
c[i] = out[i][0];
continue;
}
//~ dfs(a_, i);
c[i] = dfs(out[i]);
}
//~ for(int i=0;i<=m;i++){
//~ cout<<i<<" : ";
//~ for(auto x : out[i]) cout<<x<<" ";
//~ cout<<endl;
//~ }
//~ for(int i=0;i<=m;i++){
//~ cout<<c[i]<<" ";
//~ }
//~ cout<<endl;
//~ cout<<(int)x_.size()<<" "<<last<<endl;
//~ for(int i=0;i<last;i++){
//~ cout<<-(i + 1)<<" ";
//~ } cout<<endl;
//~ for(int i=0;i<last;i++){
//~ cout<<x_[i]<<" ";
//~ } cout<<endl;
//~ for(int i=0;i<last;i++){
//~ cout<<y_[i]<<" ";
//~ } cout<<endl;
//~ cout<<last<<endl;
const int maxAns = 4e5;
assert(last <= maxAns);
answer(c, x_, y_);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
27 ms |
7252 KB |
Output is correct |
3 |
Correct |
18 ms |
5976 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
4276 KB |
Output is correct |
6 |
Correct |
23 ms |
8916 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
27 ms |
7252 KB |
Output is correct |
3 |
Correct |
18 ms |
5976 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
4276 KB |
Output is correct |
6 |
Correct |
23 ms |
8916 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
27 ms |
8496 KB |
Output is correct |
9 |
Correct |
27 ms |
10068 KB |
Output is correct |
10 |
Correct |
48 ms |
13132 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
27 ms |
7252 KB |
Output is correct |
3 |
Correct |
18 ms |
5976 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
4276 KB |
Output is correct |
6 |
Correct |
23 ms |
8916 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
27 ms |
8496 KB |
Output is correct |
9 |
Correct |
27 ms |
10068 KB |
Output is correct |
10 |
Correct |
48 ms |
13132 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
432 KB |
Output is correct |
14 |
Correct |
58 ms |
12676 KB |
Output is correct |
15 |
Correct |
40 ms |
7156 KB |
Output is correct |
16 |
Correct |
70 ms |
10308 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
66 ms |
12580 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
856 KB |
Output is partially correct |
2 |
Correct |
30 ms |
8028 KB |
Output is correct |
3 |
Partially correct |
56 ms |
11400 KB |
Output is partially correct |
4 |
Partially correct |
70 ms |
13020 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
856 KB |
Output is partially correct |
2 |
Correct |
30 ms |
8028 KB |
Output is correct |
3 |
Partially correct |
56 ms |
11400 KB |
Output is partially correct |
4 |
Partially correct |
70 ms |
13020 KB |
Output is partially correct |
5 |
Partially correct |
82 ms |
13624 KB |
Output is partially correct |
6 |
Partially correct |
109 ms |
14320 KB |
Output is partially correct |
7 |
Partially correct |
77 ms |
14108 KB |
Output is partially correct |
8 |
Partially correct |
108 ms |
14496 KB |
Output is partially correct |
9 |
Partially correct |
75 ms |
10512 KB |
Output is partially correct |
10 |
Partially correct |
124 ms |
14612 KB |
Output is partially correct |
11 |
Partially correct |
130 ms |
14692 KB |
Output is partially correct |
12 |
Partially correct |
65 ms |
10388 KB |
Output is partially correct |
13 |
Partially correct |
56 ms |
9428 KB |
Output is partially correct |
14 |
Partially correct |
48 ms |
9080 KB |
Output is partially correct |
15 |
Partially correct |
41 ms |
9084 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
600 KB |
Output is partially correct |
17 |
Partially correct |
67 ms |
8064 KB |
Output is partially correct |
18 |
Partially correct |
44 ms |
8056 KB |
Output is partially correct |
19 |
Partially correct |
101 ms |
8572 KB |
Output is partially correct |
20 |
Partially correct |
98 ms |
11320 KB |
Output is partially correct |
21 |
Partially correct |
75 ms |
13208 KB |
Output is partially correct |
22 |
Partially correct |
119 ms |
10820 KB |
Output is partially correct |