# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107407 | 2024-11-01T07:48:38 Z | vjudge1 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 1 ms | 552 KB |
#include <bits/stdc++.h> #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long using namespace std; const int N=2e5+5; const int inf=1e9; const int mod=1e9+7; const int N1=1e6+1; vector<int>v; vector<int>v1; struct edge{ int v,time; }; int dp[1001]; signed main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n; cin>>n; string s; cin>>s; int cnt=0; int cnt1=0; for(int i=1;i<=n;i++){ if(s[i-1]=='R'){ cnt++; }else{ cnt1++; } } if(n%2==0&&abs(cnt-cnt1)!=0||n%2==1&&abs(cnt-cnt1)!=1){ cout<<"-1"; return 0; } int j=2; int l=1; int ans1=0; int ans2=0; for(int i=1;i<=n;i++){ if(s[i-1]=='R'){ ans1+=abs(j-i); ans2+=abs(l-i); l+=2; j+=2; } } int cnt3=(n+1)/2; if(cnt!=cnt3){ ans2=inf; } int cnt4=n/2; if(cnt4!=cnt){ ans1=inf; } cout<<min(ans1,ans2); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Incorrect | 0 ms | 336 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Incorrect | 0 ms | 336 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 540 KB | Output is correct |
3 | Correct | 1 ms | 504 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 0 ms | 336 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 552 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Incorrect | 0 ms | 336 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |