QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#882910 | #9961. Cows | s20hym | WA | 46ms | 144256kb | C++14 | 2.3kb | 2025-02-05 13:11:34 | 2025-02-05 13:11:35 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,f[200200],cnt=0;
namespace sub1{
int minn=0;
bool chk(int step)
{
for(int i=1;i<=n;i++) {if(f[i]) return false;cnt++;}
minn=min(minn,step);
return true;
}
void dfs(int step,int nw)
{
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<" "<<nw<<"\n";
if(minn<=step) return ;cnt++;
if(cnt>3000000) return ;
int ss=step,nn=nw,tf=1;
if(f[nw])
{
f[nw]--;
if(nw==n&&chk(step)) {f[nw]++;return ;}
else if(nw==n) step++,nw=1;
else nw++;
// cout<<"~ "<<step<<" "<<nw<<"\n";
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<"\n\n";
dfs(step,nw),f[nn]++,tf=0;
// cout<<"~~ "<<step<<" "<<nw<<"\n";
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<"\n\n";
}
else
{
int temp=nw-1;
if(temp&&f[temp])
{
f[temp]--;
if(nw==n&&chk(step)) {f[temp]++;return ;}
else if(nw==n) temp++,nw=1;
else nw++;
// cout<<"@ "<<step<<" "<<nw<<"\n";
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<"\n\n";
dfs(step,nw),f[temp]++,step=ss,nw=nn,tf=0;
// cout<<"@@ "<<step<<" "<<nw<<"\n";
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<"\n\n";
}
temp=nw+1;
if(temp!=n+1&&f[temp]>1)
{
f[temp]--;
if(nw==n&&chk(step)) {f[temp]++;return ;}
else if(nw==n) step++,nw=1;
else nw++;
// cout<<"! "<<step<<" "<<nw<<"\n";
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<"\n\n";
dfs(step,nw),f[temp]++,tf=0;
// cout<<"!! "<<step<<" "<<nw<<"\n";
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<"\n\n";
}
}
nw=nn,step=ss;
if(nw==n&&chk(step)) return ;
else if(nw==n) step++,nw=1;
else nw++;
// cout<<"$ "<<step<<" "<<nw<<"\n";
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<"\n\n";
if(tf) dfs(step,nw);tf=0;
// cout<<"$$ "<<step<<" "<<nw<<"\n";
// for(int i=1;i<=n;i++) cout<<f[i]<<" ";cout<<"\n\n";
// cout<<minn<<"\n";
return ;
}
void main()
{
for(int i=1;i<=n;i++) minn=max(minn,f[i]);
dfs(1,1),cout<<minn<<"\n";
return ;
}
}
signed main()
{
// freopen("cow.in","r",stdin);
// freopen("cow.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>f[i];
sub1::main(),exit(0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
5 5 4 0 4 6
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
3 1 4 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 46ms
memory: 144256kb
input:
1 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
8 6 0 5 5 6 3 0 6
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
6 7 6 5 2 6 8
output:
7
result:
ok 1 number(s): "7"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 5 9 3 4 3 2 5 8 2 3
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 2ms
memory: 3712kb
input:
10 1 18 3 15 0 14 20 15 14 12
output:
14
result:
ok 1 number(s): "14"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
10 1 18 3 15 0 14 20 15 15 12
output:
15
result:
ok 1 number(s): "15"
Test #10:
score: -100
Wrong Answer
time: 13ms
memory: 3712kb
input:
20 97 171 3 157 117 35 0 0 173 154 59 58 18 189 27 181 78 20 253 22
output:
23
result:
wrong answer 1st numbers differ - expected: '100', found: '23'