답안 #882972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882972 2023-12-04T09:46:53 Z LucaIlie Misspelling (JOI22_misspelling) C++17
0 / 100
1 ms 4540 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e4;
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][SIGMA + 1], maxR1[MAX_N + 1], maxR2[MAX_N + 1];

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] );
        }
    }

    dp[0][0] = 1;
    for ( int i = 1; i <= n; i++ ) {
        for ( int l = 1; l <= SIGMA; l++ ) {
            int r1 = 0, r2 = 0;
            for ( int j = i - 1; j >= 0; j-- ) {
                r1 = max( r1, maxR1[j] );
                r2 = max( r2, maxR2[j] );
                
                if ( r1 < i && r2 < i ) {
                    for ( int m = 0; m <= SIGMA; m++ ) {
                        if ( m == l )
                            continue;
                        dp[i][l] = (dp[i][l] + dp[j][m]) % MOD;
                    }
                } else if ( r1 < i && r2 >= i ) {
                    for ( int m = 0; m < l; m++ )
                        dp[i][l] = (dp[i][l] + dp[j][m]) % MOD;
                } else if ( r1 >= i && r2 < i ) {
                    for ( int m = l + 1; m <= SIGMA; 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" );
    }*/

    int 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4540 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4540 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4540 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4540 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -