#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
using namespace std;
int used[5005];
int a[5005];
void solve(int n)
{
for(int i = 1;i<=n;i++)
used[i] = 0;
int l = 1;
int r = n-1;
int start;
while(l<=r)
{
int mid = (l+r)/2;
if(query(mid, n)==n-1)
{
start = mid;
l = mid + 1;
}
else
{
r = mid - 1;
}
}
a[start] = 1;
used[1] = start;
if(start-1)
{
int k = 1 + query(start-1, start);
a[start-1] = k;
used[k] = start - 1;
}
int k = 1 + query(start, start+1);
a[start+1] = k;
used[k] = start + 1;
for(int i = start-2;i;i--)
{
int s = query(i, i + 1);
int m1, m2;
m1 = a[i+1] + s;
m2 = a[i+1] - s;
if(m1>n)
{
used[m2] = i;
a[i] = m2;
continue;
}
if(m2<=0)
{
used[m1] = i;
a[i] = m1;
continue;
}
if(used[m1])
{
a[i] = m2;
used[m2] = i;
continue;
}
if(used[m2])
{
a[i] = m1;
used[m1] = i;
continue;
}
int ss = query(i, i + 2);
if((max(a[i+2], min(m1,a[i+1])) - min(a[i+1], min(m1, a[i+2]))) == ss)
{
a[i] = m1;
used[m1] = i;
}
else
{
a[i] = m2;
used[m2] = i;
}
}
for(int i = start+2;i<=n;i++)
{
int s = query(i-1, i);
int m1, m2;
m1 = a[i-1] + s;
m2 = a[i-1] - s;
if(m1>n)
{
used[m2] = i;
a[i] = m2;
continue;
}
if(m2<=0)
{
used[m1] = i;
a[i] = m1;
continue;
}
if(used[m1])
{
a[i] = m2;
used[m2] = i;
continue;
}
if(used[m2])
{
a[i] = m1;
used[m1] = i;
continue;
}
int ss = query(i-2, i);
if((max(a[i-2], max(m1, a[i-1])) - min(a[i-2], min(a[i-1], m1))) == ss)
{
a[i] = m1;
used[m1] = i;
}
else
{
a[i] = m2;
used[m2] = i;
}
}
for(int i = 1;i<=n;i++)
{
answer(i, a[i]);
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:36:25: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
36 | int k = 1 + query(start-1, start);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |