Submission #882815

#TimeUsernameProblemLanguageResultExecution timeMemory
882815LucaIlieMisspelling (JOI22_misspelling)C++17
8 / 100
4049 ms526092 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200; const int MAX_M = 5e5; const int SIGMA = 26; const int MOD = 1e9 + 7; int l[MAX_M], r[MAX_M], t[MAX_M], dp[MAX_N + 1][MAX_N + 1][MAX_N + 1][SIGMA], maxR1[MAX_N + 1], maxR2[MAX_N + 1]; int main() { int n, m; cin >> n >> m; n++; for ( int i = 0; i < m; i++ ) { cin >> l[i] >> r[i]; l[i]++; r[i]++; if ( l[i] > r[i] ) { swap( l[i], r[i] ); t[i] = 2; maxR2[l[i]] = max( maxR2[l[i]], r[i] ); } else { t[i] = 1; maxR1[l[i]] = max( maxR1[l[i]], r[i] ); } } dp[1][0][0][0] = 1; for ( int i = 1; i < n; i++ ) { for ( int r1 = 0; r1 <= n; r1++ ) { for ( int r2 = 0; r2 <= n; r2++ ) { for ( int l = 0; l < SIGMA; l++ ) { int newR1 = max( r1, maxR1[i] ), newR2 = max( r2, maxR2[i] ); if ( newR1 <= i && newR2 <= i ) { for ( int m = 0; m < SIGMA; m++ ) dp[i + 1][newR1][newR2][m] = (dp[i + 1][newR1][newR2][m] + dp[i][r1][r2][l]) % MOD; } else if ( newR1 > i && newR2 <= i ) { for ( int m = 0; m < l; m++ ) dp[i + 1][0][newR2][m] = (dp[i + 1][0][newR2][m] + dp[i][r1][r2][l]) % MOD; dp[i + 1][newR1][newR2][l] = (dp[i + 1][newR1][newR2][l] + dp[i][r1][r2][l]) % MOD; } else if ( newR1 <= i && newR2 > i ) { for ( int m = l + 1; m < SIGMA; m++ ) dp[i + 1][newR1][0][m] = (dp[i + 1][newR1][0][m] + dp[i][r1][r2][l]) % MOD; dp[i + 1][newR1][newR2][l] = (dp[i + 1][newR1][newR2][l] + dp[i][r1][r2][l]) % MOD; } else dp[i + 1][newR1][newR2][l] = (dp[i + 1][newR1][newR2][l] + dp[i][r1][r2][l]) % MOD; } } } } /*for ( int i = 1; i <= n; i++ ) { printf( "I %d\n", i ); for ( int r1 = 0; r1 <= n; r1++ ) { printf( "r1 %d\n", r1 ); for ( int r2 = 0; r2 <= n; r2++ ) { for ( int l = 0; l < SIGMA; l++ ) printf( "%d ", dp[i][r1][r2][l] ); printf( "\n" ); } printf( "\n" ); } printf( "\n\n" ); }*/ int ans = 0; for ( int r1 = 0; r1 <= n; r1++ ) { for ( int r2 = 0; r2 <= n; r2++ ) { for ( int l = 0; l < SIGMA; l++ ) ans = (ans + dp[n][r1][r2][l]) % MOD; } } cout << ans; return 0; }
#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...