#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const int N = 3e5+5;
const ll INF = 1e18+5;
const int MOD = 1e9+7;
vector<int> x,y,c;
vector<vector<int> > nxt;
int solve(vector<int> &a){
assert(!a.empty());
int n = a.size();
int i;
bool ok = 1;
int curr = a[0];
vector<int> p1,p2;
for(i=0;i<n-1;i+=2){
if(curr != a[i] || curr != a[i+1])ok = 0;
p1.push_back(a[i]);
p2.push_back(a[i+1]);
}
if(curr != a[n-1])ok = 0;
if(ok){
return curr;
}
if(n%2){
/// we gotta add
x.push_back(0);
y.push_back(0);
int res = x.size();
p1.push_back(res*-1);
p2.push_back(a.back());
int idx1 = solve(p1);
//cerr<<idx1<<endl;
x[res-1] = idx1;
int idx2 = solve(p2);
y[res-1] = idx2;
//cerr<<idx2<<endl;
//cerr<<res*-1<<": "<<endl;
//cerr<<x[res-1]<<" "<<y[res-1]<<endl;
//for(auto x : p1)cerr<<x<<" ";
//cerr<<endl;
return res*-1;
}
else{
int idx1 = solve(p1);
int idx2 = solve(p2);
x.push_back(idx1);
y.push_back(idx2);
int res = x.size();
//cerr<<res*-1<<":"<<endl;
//cerr<<idx1<<" "<<idx2<<endl;
return res*-1;
}
}
void create_circuit(int m, vector<int> arr) {
int n = arr.size();
c.resize(m+1);
/// origin goes to first trigger
c[0] = arr[0];
int i;
nxt.assign(m+1,vector<int>());
for(i=0;i<n;i++){
if(i < n-1)
nxt[arr[i]].push_back(arr[i+1]);
else
nxt[arr[i]].push_back(0);
}
for(i=1;i<=m;i++){
int cnt = nxt[i].size();
if(cnt == 0)continue;
else if(cnt == 1){
c[i] = nxt[i][0];
}
else{
//int idx = x.size() + 1;
c[i] = solve(nxt[i]);
}
}
answer(c,x,y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
17 ms |
6288 KB |
Output is correct |
3 |
Correct |
14 ms |
5180 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
3796 KB |
Output is correct |
6 |
Correct |
21 ms |
7736 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
17 ms |
6288 KB |
Output is correct |
3 |
Correct |
14 ms |
5180 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
3796 KB |
Output is correct |
6 |
Correct |
21 ms |
7736 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
33 ms |
7344 KB |
Output is correct |
9 |
Correct |
38 ms |
8652 KB |
Output is correct |
10 |
Correct |
55 ms |
11056 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
17 ms |
6288 KB |
Output is correct |
3 |
Correct |
14 ms |
5180 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
3796 KB |
Output is correct |
6 |
Correct |
21 ms |
7736 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
33 ms |
7344 KB |
Output is correct |
9 |
Correct |
38 ms |
8652 KB |
Output is correct |
10 |
Correct |
55 ms |
11056 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
71 ms |
11756 KB |
Output is correct |
15 |
Correct |
36 ms |
5928 KB |
Output is correct |
16 |
Correct |
57 ms |
8936 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
62 ms |
11116 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
2 |
Correct |
11 ms |
2860 KB |
Output is correct |
3 |
Partially correct |
72 ms |
10268 KB |
Output is partially correct |
4 |
Correct |
17 ms |
4408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
2 |
Correct |
11 ms |
2860 KB |
Output is correct |
3 |
Partially correct |
72 ms |
10268 KB |
Output is partially correct |
4 |
Correct |
17 ms |
4408 KB |
Output is correct |
5 |
Partially correct |
87 ms |
13220 KB |
Output is partially correct |
6 |
Partially correct |
103 ms |
14004 KB |
Output is partially correct |
7 |
Partially correct |
110 ms |
13844 KB |
Output is partially correct |
8 |
Partially correct |
116 ms |
14516 KB |
Output is partially correct |
9 |
Partially correct |
77 ms |
9612 KB |
Output is partially correct |
10 |
Partially correct |
111 ms |
14540 KB |
Output is partially correct |
11 |
Partially correct |
110 ms |
14636 KB |
Output is partially correct |
12 |
Partially correct |
71 ms |
9620 KB |
Output is partially correct |
13 |
Partially correct |
63 ms |
9220 KB |
Output is partially correct |
14 |
Partially correct |
61 ms |
9060 KB |
Output is partially correct |
15 |
Partially correct |
57 ms |
8652 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
468 KB |
Output is partially correct |
17 |
Partially correct |
56 ms |
7548 KB |
Output is partially correct |
18 |
Partially correct |
58 ms |
7596 KB |
Output is partially correct |
19 |
Partially correct |
61 ms |
8208 KB |
Output is partially correct |
20 |
Partially correct |
83 ms |
10408 KB |
Output is partially correct |
21 |
Partially correct |
95 ms |
12528 KB |
Output is partially correct |
22 |
Partially correct |
74 ms |
9548 KB |
Output is partially correct |