Submission #2799142


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N,M;
vector<int> L,R,X;
vector<int> ri[303];

i64 dp[303][303][303];
i64 MOD = 1e9 + 7;
int main(){
  cin >> N >> M;
  L.resize(M);
  R.resize(M);
  X.resize(M);
  rep(i,0,M - 1) cin >> L[i] >> R[i] >> X[i];
  rep(i,0,M - 1) ri[R[i]].push_back(i);
  dp[0][0][0] = 1;

  rep(r,0,N - 1){
    rep(g,0,N - 1){
      rep(b,0,N - 1){
        int next = max({r,g,b}) + 1;
        //red
        {
          bool ok = true;
          int MIN = min({g,b});
          int MAX = max({g,b});
          for(auto idx : ri[next]){
            int cnt = 1;
            if(MAX >= L[idx]) cnt++;
            if(MIN >= L[idx]) cnt++;
            ok = ok && cnt == X[idx];
          }
          if(ok){
            dp[next][g][b] += dp[r][g][b];
            dp[next][g][b] %= MOD;
          }
        }
        {
          bool ok = true;
          int MIN = min({r,b});
          int MAX = max({r,b});
          for(auto idx : ri[next]){
            int cnt = 1;
            if(MAX >= L[idx]) cnt++;
            if(MIN >= L[idx]) cnt++;
            ok = ok && cnt == X[idx];
          }
          if(ok){
            dp[r][next][b] += dp[r][g][b];
            dp[r][next][b] %= MOD;
          }
        }
        {
          bool ok = true;
          int MIN = min({g,r});
          int MAX = max({g,r});
          for(auto idx : ri[next]){
            int cnt = 1;
            if(MAX >= L[idx]) cnt++;
            if(MIN >= L[idx]) cnt++;
            ok = ok && cnt == X[idx];
          }
          if(ok){
            dp[r][g][next] += dp[r][g][b];
            dp[r][g][next] %= MOD;
          }
        }
      }
    }
  }

  i64 ans = 0;
  rep(i,0,N - 1){
    rep(j,0,N - 1){
      ans = (dp[N][i][j] + ans) % MOD;
      ans = (dp[i][N][j] + ans) % MOD;
      ans = (dp[i][j][N] + ans) % MOD;
    }
  }

  cout << ans << endl;
}

Submission Info

Submission Time
Task E - RGB Sequence
User niuez
Language C++14 (GCC 5.4.1)
Score 800
Code Size 2027 Byte
Status
Exec Time 1373 ms
Memory 217344 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 800 / 800 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt
Case Name Status Exec Time Memory
0_00.txt 2 ms 2304 KB
0_01.txt 2 ms 2304 KB
0_02.txt 1 ms 256 KB
0_03.txt 2 ms 4480 KB
1_00.txt 1034 ms 215168 KB
1_01.txt 774 ms 215296 KB
1_02.txt 1019 ms 217344 KB
1_03.txt 1053 ms 215168 KB
1_04.txt 1104 ms 217216 KB
1_05.txt 831 ms 215296 KB
1_06.txt 1036 ms 217344 KB
1_07.txt 943 ms 215296 KB
1_08.txt 1078 ms 215296 KB
1_09.txt 1112 ms 215296 KB
1_10.txt 1045 ms 213248 KB
1_11.txt 992 ms 213248 KB
1_12.txt 773 ms 209152 KB
1_13.txt 1123 ms 217344 KB
1_14.txt 1061 ms 215296 KB
1_15.txt 1167 ms 217344 KB
1_16.txt 1079 ms 215168 KB
1_17.txt 847 ms 217344 KB
1_18.txt 1035 ms 215296 KB
1_19.txt 1025 ms 215296 KB
1_20.txt 968 ms 213248 KB
1_21.txt 978 ms 217344 KB
1_22.txt 995 ms 217344 KB
1_23.txt 1105 ms 215296 KB
1_24.txt 842 ms 215296 KB
1_25.txt 1004 ms 217344 KB
1_26.txt 971 ms 211200 KB
1_27.txt 1006 ms 215296 KB
1_28.txt 1071 ms 215296 KB
1_29.txt 866 ms 217344 KB
1_30.txt 963 ms 215296 KB
1_31.txt 1002 ms 211072 KB
1_32.txt 711 ms 217344 KB
1_33.txt 872 ms 217344 KB
1_34.txt 884 ms 211200 KB
1_35.txt 952 ms 215296 KB
1_36.txt 625 ms 206976 KB
1_37.txt 812 ms 215296 KB
1_38.txt 939 ms 217344 KB
1_39.txt 823 ms 217344 KB
1_40.txt 1373 ms 217344 KB
1_41.txt 1068 ms 217344 KB
1_42.txt 346 ms 215296 KB