#include <bits/stdc++.h>
#include "xylophone.h"
#define ll long long
#define pb push_back
#define pu push
#define ins insert
#define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff(x,a,b,c) for (auto x=a;x<=b;x+=c)
#define fd(x,a,b,c) for (auto x=a;x>=b;x-=c)
using namespace std;
const int N = 1e4+5;
const int mod = 1e9+7;
int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;}
int a[N];
int check[N];
int ans[N];
void solve(int n)
{
a[2] = query(1,2); check[2] = 0;
for (int i=3;i<=n;i++)
{
int x = query(i-1,i),y = query(i-2,i);
a[i] = x;
if (a[i-1]+a[i]==y) check[i] = check[i-1];
else check[i] = 1-check[i-1];
}
for (int i=1;i<=n;i++) ans[i] = ans[i-1]+a[i]*(1-check[i]*2);
int mx = INT_MIN,mn = INT_MAX,idx1,idx2;
for (int i=1;i<=n;i++)
{
if (mx<ans[i]) mx = ans[i],idx1 = i;
if (mn>ans[i]) mn = ans[i],idx2 = i;
}
int tmp = mn;
if (idx1<idx2)
{
for (int i=1;i<=n;i++) ans[i] = ans[i-1]+a[i]*(check[i]*2-1);
tmp = -mx;
}
for (int i=1;i<=n;i++) answer(i,ans[i]-tmp+1);
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:39:2: warning: 'idx2' may be used uninitialized in this function [-Wmaybe-uninitialized]
39 | if (idx1<idx2)
| ^~
xylophone.cpp:39:2: warning: 'idx1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
4 ms |
344 KB |
Output is correct |
18 |
Correct |
10 ms |
452 KB |
Output is correct |
19 |
Correct |
12 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
7 ms |
600 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
10 ms |
600 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
11 ms |
592 KB |
Output is correct |
28 |
Correct |
9 ms |
456 KB |
Output is correct |
29 |
Correct |
9 ms |
344 KB |
Output is correct |
30 |
Correct |
11 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
4 ms |
344 KB |
Output is correct |
18 |
Correct |
10 ms |
452 KB |
Output is correct |
19 |
Correct |
12 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
7 ms |
600 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
10 ms |
600 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
11 ms |
592 KB |
Output is correct |
28 |
Correct |
9 ms |
456 KB |
Output is correct |
29 |
Correct |
9 ms |
344 KB |
Output is correct |
30 |
Correct |
11 ms |
600 KB |
Output is correct |
31 |
Correct |
13 ms |
592 KB |
Output is correct |
32 |
Correct |
26 ms |
600 KB |
Output is correct |
33 |
Correct |
57 ms |
696 KB |
Output is correct |
34 |
Correct |
58 ms |
696 KB |
Output is correct |
35 |
Correct |
55 ms |
856 KB |
Output is correct |
36 |
Correct |
56 ms |
592 KB |
Output is correct |
37 |
Correct |
72 ms |
692 KB |
Output is correct |
38 |
Correct |
49 ms |
848 KB |
Output is correct |
39 |
Correct |
50 ms |
592 KB |
Output is correct |
40 |
Correct |
60 ms |
344 KB |
Output is correct |
41 |
Correct |
75 ms |
448 KB |
Output is correct |
42 |
Correct |
55 ms |
696 KB |
Output is correct |
43 |
Correct |
52 ms |
344 KB |
Output is correct |
44 |
Correct |
58 ms |
592 KB |
Output is correct |
45 |
Correct |
59 ms |
948 KB |
Output is correct |
46 |
Correct |
49 ms |
716 KB |
Output is correct |
47 |
Correct |
41 ms |
444 KB |
Output is correct |
48 |
Correct |
62 ms |
448 KB |
Output is correct |
49 |
Correct |
44 ms |
456 KB |
Output is correct |
50 |
Correct |
47 ms |
600 KB |
Output is correct |
51 |
Correct |
53 ms |
1216 KB |
Output is correct |
52 |
Correct |
60 ms |
456 KB |
Output is correct |
53 |
Correct |
59 ms |
856 KB |
Output is correct |
54 |
Correct |
43 ms |
452 KB |
Output is correct |
55 |
Correct |
51 ms |
956 KB |
Output is correct |
56 |
Correct |
53 ms |
708 KB |
Output is correct |
57 |
Correct |
53 ms |
700 KB |
Output is correct |
58 |
Correct |
51 ms |
592 KB |
Output is correct |
59 |
Correct |
60 ms |
344 KB |
Output is correct |
60 |
Correct |
52 ms |
700 KB |
Output is correct |