Submission #2110756


Source Code Expand



#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n, m, i, j, k;
	cin >> n >> m;
	vector<pair<pll, ll> > rlx(m);
	for (i = 0; i < m; i++) {
		cin >> rlx[i].first.second >> rlx[i].first.first >> rlx[i].second;

	}
	sort(rlx.begin(), rlx.end());

	/*
	rep(i, m) {
	cout << rlx[i].first.first << " " << rlx[i].first.second << " " << rlx[i].second << endl;
	}
	cout << endl;
	//*/

	vector<vll> rgb(n + 1, vll(n + 1, vl(n + 1)));
	vector<vector<vector<bool> > > used(n + 1, vector<vector<bool> >(n + 1, vector<bool>(n + 1)));
	rgb[0][0][0] = 1;
	j = 0;
	rep1(i, n) {
		rep(r, i) {
			rep(g, i) {
				if (!used[r][g][i - 1]) {
					(rgb[i][g][i - 1] += rgb[r][g][i - 1]) %= MOD;
					(rgb[r][i][i - 1] += rgb[r][g][i - 1]) %= MOD;
					(rgb[r][g][i] += rgb[r][g][i - 1]) %= MOD;
					used[r][g][i - 1] = true;
				}
			}
			rep(b, i) {
				if (!used[r][i - 1][b]) {
					(rgb[i][i - 1][b] += rgb[r][i - 1][b]) %= MOD;
					(rgb[r][i - 1][i] += rgb[r][i - 1][b]) %= MOD;
					(rgb[r][i][b] += rgb[r][i - 1][b]) %= MOD;
					used[r][i - 1][b] = true;
				}
			}
		}
		rep(g, i) {
			rep(b, i) {
				if (!used[i - 1][g][b]) {
					(rgb[i][g][b] += rgb[i - 1][g][b]) %= MOD;
					(rgb[i - 1][i][b] += rgb[i - 1][g][b]) %= MOD;
					(rgb[i - 1][g][i] += rgb[i - 1][g][b]) %= MOD;
					used[i - 1][g][b] = true;
				}
			}
		}



		while (j < m && i == rlx[j].first.first) {
			int x = rlx[j].second;
			int l = rlx[j].first.second;
			if (x == 1) {
				for (int g = l; g <= i; g++) {
					for (int b = 0; b <= i; b++) {
						rgb[i][g][b] = rgb[i][b][g] = 0;
						rgb[g][i][b] = rgb[b][i][g] = 0;
						rgb[g][b][i] = rgb[b][g][i] = 0;
					}
				}
			}
			else if (x == 2) {
				for (int g = l; g <= i; g++) {
					for (int b = l; b <= i; b++) {
						rgb[i][g][b] = rgb[i][b][g] = 0;
						rgb[g][i][b] = rgb[b][i][g] = 0;
						rgb[g][b][i] = rgb[b][g][i] = 0;
					}
				}
				for (int g = 0; g < l; g++) {
					for (int b = 0; b < l; b++) {
						rgb[i][g][b] = rgb[i][b][g] = 0;
						rgb[g][i][b] = rgb[b][i][g] = 0;
						rgb[g][b][i] = rgb[b][g][i] = 0;
					}
				}
			}
			else {
				for (int g = 0; g <= i; g++) {
					for (int b = 0; b < l; b++) {
						rgb[i][g][b] = rgb[i][b][g] = 0;
						rgb[g][i][b] = rgb[b][i][g] = 0;
						rgb[g][b][i] = rgb[b][g][i] = 0;
					}
				}
			}
			j++;
		}

		/*
		rep(r, i + 1) {
		rep(g, i + 1) {
		rep(b, i + 1) {
		cout << rgb[r][g][b] << " ";
		}
		cout << endl;
		}
		cout << endl;
		}
		//*/
	}
	ll ans = 0;
	rep(g, n + 1) {
		rep(b, n + 1) {
			ans += rgb[n][g][b] %= MOD;
			ans += rgb[g][n][b] %= MOD;
			ans += rgb[b][g][n] %= MOD;
		}
	}
	cout << ans << endl;
}

Submission Info

Submission Time
Task E - RGB Sequence
User fuppy0716
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3649 Byte
Status WA
Exec Time 2042 ms
Memory 226048 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 4
AC × 20
WA × 26
TLE × 1
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 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 AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
1_00.txt WA 1076 ms 215296 KB
1_01.txt WA 1516 ms 219648 KB
1_02.txt WA 1250 ms 226048 KB
1_03.txt AC 1125 ms 219648 KB
1_04.txt WA 1070 ms 224000 KB
1_05.txt WA 1462 ms 218112 KB
1_06.txt WA 1220 ms 224000 KB
1_07.txt AC 1449 ms 218112 KB
1_08.txt WA 1097 ms 218112 KB
1_09.txt WA 1484 ms 219648 KB
1_10.txt WA 1186 ms 213888 KB
1_11.txt AC 1434 ms 213888 KB
1_12.txt WA 1855 ms 201344 KB
1_13.txt WA 1488 ms 226048 KB
1_14.txt WA 1265 ms 218112 KB
1_15.txt AC 1062 ms 222464 KB
1_16.txt WA 1087 ms 219648 KB
1_17.txt WA 1651 ms 224000 KB
1_18.txt WA 986 ms 218112 KB
1_19.txt AC 1083 ms 220160 KB
1_20.txt WA 1221 ms 213888 KB
1_21.txt WA 1264 ms 224000 KB
1_22.txt WA 930 ms 222464 KB
1_23.txt AC 1100 ms 219648 KB
1_24.txt WA 1965 ms 219648 KB
1_25.txt WA 1203 ms 224000 KB
1_26.txt WA 789 ms 206848 KB
1_27.txt AC 893 ms 219648 KB
1_28.txt WA 927 ms 219648 KB
1_29.txt AC 910 ms 222464 KB
1_30.txt WA 792 ms 215296 KB
1_31.txt AC 1042 ms 209664 KB
1_32.txt TLE 2042 ms 222464 KB
1_33.txt AC 779 ms 224000 KB
1_34.txt WA 643 ms 209664 KB
1_35.txt AC 708 ms 220160 KB
1_36.txt AC 1962 ms 198656 KB
1_37.txt AC 880 ms 218112 KB
1_38.txt AC 715 ms 224000 KB
1_39.txt AC 875 ms 224000 KB
1_40.txt WA 723 ms 224000 KB
1_41.txt WA 1706 ms 226048 KB
1_42.txt AC 1739 ms 224000 KB