Submission #262846

#TimeUsernameProblemLanguageResultExecution timeMemory
262846ElyesChaabouniLinear Garden (IOI08_linear_garden)C++14
80 / 100
104 ms65540 KiB
/*#pragma GCC optimize("O3")*/ #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> #define eps 1e-9 #define MOD1 998244353 #define MOD2 1000000007 #define INV_10 299473306 #define INF 1000000000 #define PI 3.14159265358979323846 using namespace std; int dp[1000000][3][3][2]; bool a[1000000]; int n, m, cu, pp, ll; int solve(int idx, int p, int l, bool b) { if(idx==n) return 1; if(dp[idx][p][l][b]!=-1) return dp[idx][p][l][b]; dp[idx][p][l][b]=0; if(a[idx]) { if(p < 2) { pp=p; ll=l; pp++; ll--; ll=max(ll, 0); dp[idx][p][l][b]+=solve(idx+1, pp, ll, b); dp[idx][p][l][b]%=m; } if(l < 2) { pp=p; ll=l; pp--; ll++; pp=max(0, pp); dp[idx][p][l][b]+=solve(idx+1, pp, ll, 1); dp[idx][p][l][b]%=m; } } else { if(l < 2) { pp=p; ll=l; pp--; ll++; pp=max(0, pp); dp[idx][p][l][b]+=solve(idx+1, pp, ll, b); dp[idx][p][l][b]%=m; } if(p < 2 && b) { pp=p; ll=l; pp++; ll--; ll=max(ll, 0); dp[idx][p][l][b]+=solve(idx+1, pp, ll, b); dp[idx][p][l][b]%=m; } } return dp[idx][p][l][b]; } int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m; char c; for(int i = 0; i < n; i++) { cin >> c; if(c=='P') a[i]=1; } for(int i = 0; i <= n; i++) for(int j = 0; j < 3; j++) for(int k = 0; k < 3; k++) for(int l = 0; l < 3; l++) dp[i][j][k][l]=-1; cout << solve(0, 0, 0, 0) << '\n'; } //size

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:86:20: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
   86 |      dp[i][j][k][l]=-1;
      |      ~~~~~~~~~~~~~~^~~
linear_garden.cpp:85:22: note: within this loop
   85 |     for(int l = 0; l < 3; l++)
      |                    ~~^~~
linear_garden.cpp:86:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   86 |      dp[i][j][k][l]=-1;
      |      ~~~~~~~~~~~~~^
linear_garden.cpp:86:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
linear_garden.cpp:86:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
#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...