Submission #882977

#TimeUsernameProblemLanguageResultExecution timeMemory
882977LucaIlieMisspelling (JOI22_misspelling)C++17
28 / 100
4003 ms12484 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], maxR1[MAX_N + 1], maxR2[MAX_N + 1]; int dp[MAX_N + 1][SIGMA]; int main() { int n, m; cin >> n >> m; for ( int i = 0; i < m; i++ ) { cin >> 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] ); } } for ( int l = 0; l < SIGMA; l++ ) dp[1][l] = 1; for ( int i = 1; i <= n; i++ ) { int r1 = maxR1[i - 1], p1 = i - 1; while ( r1 < i && p1 > 0 ) { p1--; r1 = max( r1, maxR1[p1] ); } int r2 = maxR2[i - 1], p2 = i - 1; while ( r2 < i && p2 > 0 ) { p2--; r2 = max( r2, maxR2[p2] ); } for ( int j = i - 1; j > max( p1, p2 ); j-- ) { for ( int l = 0; l < SIGMA; l++ ) { for ( int m = 0; m < SIGMA; m++ ) { if ( m == l ) continue; dp[i][l] = (dp[i][l] + dp[j][m]) % MOD; } } } if ( p1 > p2 ) { for ( int j = p1; j > p2; j-- ) { for ( int l = 0; l < SIGMA; l++ ) { for ( int m = l + 1; m < SIGMA; m++ ) dp[i][l] = (dp[i][l] + dp[j][m]) % MOD; } } } else { for ( int j = p2; j > p1; j-- ) { for ( int l = 0; l < SIGMA; l++ ) { for ( int m = 0; m < l; m++ ) dp[i][l] = (dp[i][l] + dp[j][m]) % MOD; } } } } /*for ( int i = 0; i <= n; i++ ) { for ( int l = 0; l < SIGMA; l++ ) printf( "%d ", dp[i][l] ); printf( "\n" ); }*/ long long ans = 0; for ( int i = 1; i <= n; i++ ) { for ( int l = 0; l < SIGMA; l++ ) ans = (ans + dp[i][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...