Submission #1107407

#TimeUsernameProblemLanguageResultExecution timeMemory
1107407vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
15 / 100
1 ms552 KiB
#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 (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:32:14: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   32 |     if(n%2==0&&abs(cnt-cnt1)!=0||n%2==1&&abs(cnt-cnt1)!=1){
      |        ~~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...