Submission #340795

#TimeUsernameProblemLanguageResultExecution timeMemory
340795Sho10Linear Garden (IOI08_linear_garden)C++14
100 / 100
17 ms10248 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10 #define ll long long #define double long double #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #define f first #define s second #define pb push_back #define mp make_pair #define pi pair #define rc(s) return cout<<s,0 #define endl '\n' #define mod 1000007 #define PI 3.14159265359 #define MAXN 100005 #define INF 1000000005 #define LINF 1000000000000000005ll #define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ll n,m,p[1000005],res=1; string s; int32_t main(){ CODE_START; cin>>n>>m; cin>>s; p[0]=1; for(ll i=1;i<=n;i++) { p[i]=p[i-1]*2; p[i]%=m; } ll mn=0,mx=0,cur=0; for(ll i=0;i<n;i++) { if(s[i]=='L'){ cur++; mx=max(mx,cur); }else { ll r=n-i-1; ll st,dr; st=cur+1; dr=max(st,mx); if(dr-mn==1){ res+=p[r>>1]+p[r+1 >> 1]-1; res+=m; res%=m; }else if(dr-mn==2){ res+=p[r+(cur==mn) >> 1]; res%=m; } cur--; mn=min(mn,cur); } } cout<<res%m<<endl; }

Compilation message (stderr)

linear_garden.cpp: In function 'int32_t main()':
linear_garden.cpp:45:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |         res+=p[r>>1]+p[r+1 >> 1]-1;
      |                        ~^~
linear_garden.cpp:49:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     res+=p[r+(cur==mn) >> 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...