#include <bits/stdc++.h>
#define ll long long
//#define endl '\n'
#define pb push_back
using namespace std;
const ll mx=100006;
#include "xylophone.h"
static int A[5000];
void solve(int n) {
map<pair<int,int>,int>mp;
for(int i=1;i<=n;i++)
{
if(i+1<=n)
mp[{i,i+1}]=query(i, i+1);
if(i+2<=n)
mp[{i,i+2}]=query(i, i+2);
}
ll sa[n+1],sb[n+1];
deque<bool>v;
bool m=false;
v.push_back(m);
for(int i = 1; i <= n-2; i++)
{
int c=mp[{i,i+2}],x=mp[{i,i+1}],y=mp[{i+1,i+2}];
if(c!=x+y)
{
if(m)m=0;
else m=1;
}
v.push_back(m);
}
sa[1]=1;
sb[1]=1;
ll mna=1,mnb=1;
for(int i=2;i<=n;i++)
{
if(v.front())
{
sa[i]=sa[i-1]+mp[{i-1,i}];
sb[i]=sb[i-1]-mp[{i-1,i}];
}
else
{
sa[i]=sa[i-1]-mp[{i-1,i}];
sb[i]=sb[i-1]+mp[{i-1,i}];
}
mna=min(mna,sa[i]);
mnb=min(mnb,sb[i]);
v.pop_front();
}
ll x=1-mna,y=1-mnb,z=-1;
for(int i=1;i<=n;i++)
{
sa[i]+=x;
sb[i]+=y;
if(sa[i]==1&&z==-1)z=1;
if(sb[i]==1&&z==-1)z=0;
}
for(int i=1;i<=n;i++)
{
if(z)
answer(i, sa[i]);
else
answer(i, sb[i]);
}
}
Compilation message
xylophone.cpp:9:12: warning: 'A' defined but not used [-Wunused-variable]
9 | static int A[5000];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
300 KB |
Output is correct |
6 |
Correct |
2 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
300 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
300 KB |
Output is correct |
6 |
Correct |
2 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
300 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
9 ms |
336 KB |
Output is correct |
18 |
Correct |
15 ms |
344 KB |
Output is correct |
19 |
Correct |
17 ms |
376 KB |
Output is correct |
20 |
Correct |
15 ms |
372 KB |
Output is correct |
21 |
Correct |
14 ms |
400 KB |
Output is correct |
22 |
Correct |
17 ms |
316 KB |
Output is correct |
23 |
Correct |
18 ms |
380 KB |
Output is correct |
24 |
Correct |
18 ms |
372 KB |
Output is correct |
25 |
Correct |
17 ms |
336 KB |
Output is correct |
26 |
Correct |
14 ms |
336 KB |
Output is correct |
27 |
Correct |
14 ms |
336 KB |
Output is correct |
28 |
Correct |
17 ms |
344 KB |
Output is correct |
29 |
Correct |
15 ms |
360 KB |
Output is correct |
30 |
Correct |
17 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
300 KB |
Output is correct |
6 |
Correct |
2 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
300 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
9 ms |
336 KB |
Output is correct |
18 |
Correct |
15 ms |
344 KB |
Output is correct |
19 |
Correct |
17 ms |
376 KB |
Output is correct |
20 |
Correct |
15 ms |
372 KB |
Output is correct |
21 |
Correct |
14 ms |
400 KB |
Output is correct |
22 |
Correct |
17 ms |
316 KB |
Output is correct |
23 |
Correct |
18 ms |
380 KB |
Output is correct |
24 |
Correct |
18 ms |
372 KB |
Output is correct |
25 |
Correct |
17 ms |
336 KB |
Output is correct |
26 |
Correct |
14 ms |
336 KB |
Output is correct |
27 |
Correct |
14 ms |
336 KB |
Output is correct |
28 |
Correct |
17 ms |
344 KB |
Output is correct |
29 |
Correct |
15 ms |
360 KB |
Output is correct |
30 |
Correct |
17 ms |
336 KB |
Output is correct |
31 |
Correct |
36 ms |
504 KB |
Output is correct |
32 |
Correct |
51 ms |
708 KB |
Output is correct |
33 |
Correct |
40 ms |
916 KB |
Output is correct |
34 |
Correct |
86 ms |
968 KB |
Output is correct |
35 |
Correct |
83 ms |
988 KB |
Output is correct |
36 |
Correct |
81 ms |
1004 KB |
Output is correct |
37 |
Correct |
82 ms |
1076 KB |
Output is correct |
38 |
Correct |
68 ms |
944 KB |
Output is correct |
39 |
Correct |
56 ms |
912 KB |
Output is correct |
40 |
Correct |
93 ms |
976 KB |
Output is correct |
41 |
Correct |
78 ms |
1000 KB |
Output is correct |
42 |
Correct |
83 ms |
1080 KB |
Output is correct |
43 |
Correct |
74 ms |
968 KB |
Output is correct |
44 |
Correct |
94 ms |
984 KB |
Output is correct |
45 |
Correct |
69 ms |
996 KB |
Output is correct |
46 |
Correct |
74 ms |
952 KB |
Output is correct |
47 |
Correct |
86 ms |
924 KB |
Output is correct |
48 |
Correct |
70 ms |
1036 KB |
Output is correct |
49 |
Correct |
86 ms |
1000 KB |
Output is correct |
50 |
Correct |
78 ms |
928 KB |
Output is correct |
51 |
Correct |
91 ms |
972 KB |
Output is correct |
52 |
Correct |
71 ms |
1036 KB |
Output is correct |
53 |
Correct |
52 ms |
1012 KB |
Output is correct |
54 |
Correct |
80 ms |
928 KB |
Output is correct |
55 |
Correct |
81 ms |
968 KB |
Output is correct |
56 |
Correct |
83 ms |
1132 KB |
Output is correct |
57 |
Correct |
87 ms |
968 KB |
Output is correct |
58 |
Correct |
83 ms |
940 KB |
Output is correct |
59 |
Correct |
91 ms |
1100 KB |
Output is correct |
60 |
Correct |
100 ms |
968 KB |
Output is correct |