Submission #2107791
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]);
(ans += rgb[g][n][b]);
(ans += rgb[b][g][n]);
}
}
cout << ans << endl;
}
Submission Info
Submission Time |
|
Task |
E - RGB Sequence |
User |
fuppy0716 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3643 Byte |
Status |
WA |
Exec Time |
1716 ms |
Memory |
224000 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 800 |
Status |
|
|
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 |
918 ms |
215296 KB |
1_01.txt |
WA |
1198 ms |
221696 KB |
1_02.txt |
WA |
1003 ms |
224000 KB |
1_03.txt |
AC |
931 ms |
219648 KB |
1_04.txt |
WA |
857 ms |
224000 KB |
1_05.txt |
WA |
1181 ms |
218112 KB |
1_06.txt |
WA |
967 ms |
224000 KB |
1_07.txt |
AC |
1160 ms |
218112 KB |
1_08.txt |
WA |
843 ms |
220160 KB |
1_09.txt |
WA |
1170 ms |
219648 KB |
1_10.txt |
WA |
926 ms |
213888 KB |
1_11.txt |
AC |
1094 ms |
213888 KB |
1_12.txt |
WA |
1425 ms |
201344 KB |
1_13.txt |
WA |
1183 ms |
224000 KB |
1_14.txt |
WA |
970 ms |
220160 KB |
1_15.txt |
AC |
818 ms |
222464 KB |
1_16.txt |
WA |
885 ms |
219648 KB |
1_17.txt |
WA |
1223 ms |
224000 KB |
1_18.txt |
WA |
777 ms |
218112 KB |
1_19.txt |
AC |
836 ms |
218112 KB |
1_20.txt |
WA |
977 ms |
213888 KB |
1_21.txt |
WA |
1011 ms |
224000 KB |
1_22.txt |
WA |
738 ms |
222464 KB |
1_23.txt |
AC |
906 ms |
219648 KB |
1_24.txt |
WA |
1580 ms |
219648 KB |
1_25.txt |
WA |
970 ms |
224000 KB |
1_26.txt |
WA |
628 ms |
206848 KB |
1_27.txt |
AC |
697 ms |
219648 KB |
1_28.txt |
WA |
776 ms |
219648 KB |
1_29.txt |
AC |
829 ms |
222464 KB |
1_30.txt |
WA |
639 ms |
215296 KB |
1_31.txt |
AC |
867 ms |
209664 KB |
1_32.txt |
WA |
1716 ms |
222464 KB |
1_33.txt |
AC |
766 ms |
224000 KB |
1_34.txt |
WA |
595 ms |
209664 KB |
1_35.txt |
AC |
667 ms |
218112 KB |
1_36.txt |
AC |
1437 ms |
200704 KB |
1_37.txt |
AC |
677 ms |
218112 KB |
1_38.txt |
AC |
606 ms |
224000 KB |
1_39.txt |
AC |
680 ms |
224000 KB |
1_40.txt |
WA |
548 ms |
224000 KB |
1_41.txt |
WA |
1292 ms |
224000 KB |
1_42.txt |
AC |
1322 ms |
224000 KB |