QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556637#7713. Rikka with Mutexship2077#WA 44ms4380kbC++23739b2024-09-10 19:51:132024-09-10 19:51:14

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 19:51:14]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:4380kb
  • [2024-09-10 19:51:13]
  • 提交

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+res>=0;
		if (sum+Min<0) return 0;
		sum+=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: 3796kb

input:

4
VPP
VPPVVVVPPPPPPPP
VPPPPPPPPPPPPPP
P

output:

2
3
14
-1

result:

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

Test #2:

score: -100
Wrong Answer
time: 44ms
memory: 4380kb

input:

1000
VPPVVVPPPPPVVVVVVPPPPPPPPPPVVVVVVVVVVVPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV...

output:

46
335
49
339
470
745
105
70
351
200
43612
93945
82500
99158
94960
87620
86384
80420
73572
92032
52670
30885
79876
5
72163
26054
82086
3
62572
31649
555
46
3
35
195
248
748
558
100
18
885
902
1
3
571
6
429
2
898
911
274
669
186
258
379
2
582
1
869
1
752
173
766
862
891
852
156
330
4
614
711
4
202
19...

result:

wrong answer 3rd numbers differ - expected: '50', found: '49'