QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556646#7713. Rikka with Mutexship2077#AC ✓40ms4304kbC++23743b2024-09-10 19:55:132024-09-10 19:55:14

Judging History

This is the latest submission verdict.

  • [2024-09-10 19:55:14]
  • Judged
  • Verdict: AC
  • Time: 40ms
  • Memory: 4304kb
  • [2024-09-10 19:55:13]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=1e5+5;
string str;int n,a[M];
bool check(int mid){
	long long sum=0;int pos=0;
	while (pos<n){
		int res=a[pos],Min=a[pos];
		while (res<0&&pos+1<n)
			Min=min(Min,res+=a[++pos]);
		if (res<0) return sum+Min>=0;
		if (sum+Min<0) return 0;
		sum+=1ll*res*mid; pos++;
	} return 1;
}
void solve(){
	cin>>str;n=str.length();
	for (int i=0;i<n;i++) a[i]=str[i]=='V'?1:-1;
	if (str[0]=='P') return puts("-1"),void();
	int l=1,r=n,ans=0;
	while (l<=r){
		int mid=l+r>>1;
		if (check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;cin>>T;while (T--) solve(); return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3872kb

input:

4
VPP
VPPVVVVPPPPPPPP
VPPPPPPPPPPPPPP
P

output:

2
3
14
-1

result:

ok 4 number(s): "2 3 14 -1"

Test #2:

score: 0
Accepted
time: 40ms
memory: 4304kb

input:

1000
VPPVVVPPPPPVVVVVVPPPPPPPPPPVVVVVVVVVVVPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV...

output:

46
335
50
339
470
745
105
71
351
200
51031
93945
82501
99158
94960
87620
86384
80421
73576
92033
52670
30885
79876
5
72163
26055
82086
3
62572
31654
555
46
3
35
196
248
748
558
101
18
885
902
1
3
571
6
429
2
898
911
278
670
187
258
379
2
583
1
869
1
752
173
766
862
891
852
157
330
4
614
711
4
202
19...

result:

ok 1000 numbers