#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=2e5;
int tab[2*N+10];
int stationary(int n)
{
int ans=n+1,g=n;
for(int i=1;i<=n;i++)
{
vector<int> st;
int cnt=0;
for(int j=i+1;j<=n;j++)
{
if(tab[2*j-1]==-1 && tab[2*j-2]==-1)
st.push_back(j);
else if(tab[2*j-1]==1 && tab[2*j-2]==1)
{
if(st.empty())
cnt++;
else
st.pop_back();
}
}
if(i!=1)
{
if(tab[1]==1)
{
if(st.empty())
cnt++;
else
st.pop_back();
}
if(tab[2]==1)
{
if(st.empty())
cnt++;
else
st.pop_back();
}
}
for(int j=2;j<i;j++)
{
if(tab[2*j-1]==-1 && tab[2*j]==-1)
st.push_back(j);
else if(tab[2*j-1]==1 && tab[2*j]==1)
{
if(st.empty())
cnt++;
else
st.pop_back();
}
}
if(i==1)
cnt++;
if(tab[2*i-1]==1)
cnt++;
st.push_back(i);
int w=st[st.size()-1-cnt];
if(w<ans || (w==ans && i>g))
{
ans=w;
g=i;
}
}
return g;
}
int moving(int n,int r)
{
int ans=n+1,g=n;
int fl;
for(int i=1;i<2*n;i++)
{
if(tab[i]==1)
continue;
fl=(i+2)/2;
break;
}
for(int i=fl;i<=n;i++)
{
vector<int> st;
int cnt=0;
for(int j=i-1;j>1;j--)
{
if(tab[2*j-1]==1 && tab[2*j-2]==1)
st.push_back(j);
else if(tab[2*j-1]==-1 && tab[2*j-2]==-1)
{
if(st.empty())
cnt++;
else
st.pop_back();
}
}
for(int j=n;j>i;j--)
{
if(tab[2*j-1]==1 && tab[2*j-2]==1)
st.push_back(j);
else if(tab[2*j-1]==-1 && tab[2*j-2]==-1)
{
if(st.empty())
cnt++;
else
st.pop_back();
}
}
if(i!=1 && tab[2*i-1]==-1)
cnt++;
st.push_back(i);
int w=st[st.size()-1-cnt];
w=((i-(r-(w-i))-1)%n+n)%n+1;
if(w<ans || (w==ans && i>g))
{
ans=w;
g=i;
}
}
return g;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,r,x;
cin>>n>>r>>x;
for(int i=1;i<2*n;i++)
{
cin>>tab[i];
if(tab[i]>x)
tab[i]=1;
else
tab[i]=-1;
}
if(x==1)
cout<<n<<"\n";
else if(2<=x && x<=n+1)
cout<<moving(n,r)<<"\n";
else
cout<<stationary(n)<<"\n";
return 0;
}
Compilation message
archery.cpp: In function 'int moving(int, int)':
archery.cpp:84:14: warning: 'fl' may be used uninitialized in this function [-Wmaybe-uninitialized]
84 | for(int j=i-1;j>1;j--)
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
27 ms |
332 KB |
Output isn't correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
9 ms |
352 KB |
Output isn't correct |
4 |
Incorrect |
1866 ms |
620 KB |
Output isn't correct |
5 |
Execution timed out |
2086 ms |
4036 KB |
Time limit exceeded |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
8 |
Incorrect |
880 ms |
716 KB |
Output isn't correct |
9 |
Incorrect |
1535 ms |
760 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
332 KB |
Output isn't correct |
11 |
Execution timed out |
2079 ms |
724 KB |
Time limit exceeded |
12 |
Incorrect |
30 ms |
332 KB |
Output isn't correct |
13 |
Execution timed out |
2005 ms |
3592 KB |
Time limit exceeded |
14 |
Incorrect |
103 ms |
416 KB |
Output isn't correct |
15 |
Execution timed out |
2087 ms |
972 KB |
Time limit exceeded |
16 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
17 |
Incorrect |
8 ms |
344 KB |
Output isn't correct |
18 |
Incorrect |
17 ms |
332 KB |
Output isn't correct |
19 |
Incorrect |
50 ms |
372 KB |
Output isn't correct |
20 |
Incorrect |
81 ms |
332 KB |
Output isn't correct |
21 |
Incorrect |
1152 ms |
836 KB |
Output isn't correct |
22 |
Execution timed out |
2078 ms |
916 KB |
Time limit exceeded |
23 |
Execution timed out |
2081 ms |
4652 KB |
Time limit exceeded |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
6 ms |
332 KB |
Output is correct |
26 |
Correct |
111 ms |
376 KB |
Output is correct |
27 |
Execution timed out |
2045 ms |
740 KB |
Time limit exceeded |
28 |
Execution timed out |
2067 ms |
3416 KB |
Time limit exceeded |
29 |
Correct |
9 ms |
360 KB |
Output is correct |
30 |
Correct |
100 ms |
420 KB |
Output is correct |
31 |
Correct |
1368 ms |
716 KB |
Output is correct |
32 |
Execution timed out |
2081 ms |
4684 KB |
Time limit exceeded |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
18 ms |
372 KB |
Output is correct |
36 |
Correct |
25 ms |
332 KB |
Output is correct |
37 |
Correct |
1008 ms |
640 KB |
Output is correct |
38 |
Execution timed out |
2094 ms |
788 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
5 ms |
332 KB |
Output is correct |
41 |
Correct |
17 ms |
364 KB |
Output is correct |
42 |
Correct |
24 ms |
332 KB |
Output is correct |
43 |
Correct |
85 ms |
404 KB |
Output is correct |
44 |
Correct |
349 ms |
516 KB |
Output is correct |
45 |
Correct |
1375 ms |
876 KB |
Output is correct |
46 |
Correct |
1846 ms |
732 KB |
Output is correct |
47 |
Execution timed out |
2088 ms |
5284 KB |
Time limit exceeded |