QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249167 | #7623. Coloring Tape | ucup-team197# | TL | 312ms | 67508kb | C++17 | 3.2kb | 2023-11-12 01:41:47 | 2023-11-12 01:41:47 |
Judging History
answer
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <array>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
int n,m,k;
ll dp[505][1<<14];
int con[505][15][15];
int col;
ll ways;
int sz=0;
int pos_t[15];
bool can[15][15];
int mn[15],mx[15];
void exh(int id, int mk, int done){
vector<array<int, 3>> v;
v.push_back({id, mk, done});
while(!v.empty()){
auto [id, mk, done] = v.back();
v.pop_back();
int new_id, new_mk, new_done;
if(id == 0){
if(done == 0){
dp[col][mk] += ways;
}
continue;
}
if(done!=pos_t[id]+1){
if(can[pos_t[id]][done-1]){
new_id = id - 1;
new_mk = mk|(1<<(done-1));
new_done = pos_t[id];
v.push_back({new_id, new_mk, new_done});
}
}
else{
for(int i=pos_t[id]; i>pos_t[id-1] ;i--){
if(can[i][pos_t[id]]){
new_id = id - 1;
new_mk = mk|(1<<i);
new_done = i;
v.push_back({new_id, new_mk, new_done});
}
}
}
}
}
void exh2(int id,int mk,int done){
if(id==0){
if(done==0){
dp[col][mk]+=ways;
}
return;
}
if(done!=pos_t[id]+1){
if(can[pos_t[id]][done-1]) exh2(id-1,mk|(1<<(done-1)),pos_t[id]);
return;
}
for(int i=pos_t[id]; i>pos_t[id-1] ;i--){
if(can[i][pos_t[id]]) exh2(id-1,mk|(1<<i),i);
}
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> m >> k;
for(int i=1; i<=k ;i++){
int c,x,y,diff;cin >> c >> x >> y >> diff;
x--;y--;
diff++;
if(con[c][x][y]+diff==3) return cout << "0\n",0;
if(c==1 && diff==1) return cout << "0\n",0;
con[c][x][y]|=diff;
}
dp[1][(1<<n)-1]=1;
for(int r=1; r<m ;r++){
for(int i=0; i<n ;i++){
for(int j=i; j<n ;j++){
can[i][j]=true;
}
}
for(int i=0; i<n ;i++){
int b1=i;
int b2=n;
for(int j=i; j<n ;j++){
if(con[r+1][i][j]==1) b1=max(b1,j);
if(con[r+1][i][j]==2) b2=min(b2,j);
}
if(b1!=i){
int j=b1;
if(con[r+1][i][j]==1){//same constraint
for(int l=0; l<=i ;l++){
for(int r=i; r<j ;r++){
can[l][r]=false;
}
}
}
}
if(b2!=n){//diff constraint
int j=b2;
for(int l=0; l<=i ;l++){
for(int r=j; r<n ;r++){
can[l][r]=false;
}
}
}
}/*
for(int i=0; i<n ;i++){
for(int j=i; j<n ;j++){
cout << can[i][j] << ' ';
}
}
cout << endl;*/
for(int i=0; i<n ;i++){
for(int j=0; j<(1<<n) ;j++){
if((j>>i)&1) dp[r][j^(1<<i)]=(dp[r][j^(1<<i)]+dp[r][j]);
}
}
for(int j=0; j<(1<<n) ;j++){
dp[r][j]%=mod;
}
col=r+1;
for(int j=1; j<(1<<n) ;j++){
ways=dp[r][j];
if(ways==0) continue;
sz=0;
pos_t[0]=-1;
for(int i=0; i<n ;i++){
if((j>>i)&1) pos_t[++sz]=i;
}
exh(sz,0,n);
}
for(int j=1; j<(1<<n) ;j++){
dp[r+1][j]%=mod;
}
}
ll ans=0;
for(int j=1; j<(1<<n) ;j++) ans=(ans+dp[m][j])%mod;
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3532kb
input:
3 5 3 3 2 3 0 4 1 2 0 5 1 3 0
output:
19
result:
ok 1 number(s): "19"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5492kb
input:
5 10 10 9 3 4 1 2 4 5 0 7 2 3 0 9 2 3 0 6 3 5 0 6 2 4 1 2 4 5 0 1 1 3 1 7 2 4 0 10 2 3 0
output:
1514
result:
ok 1 number(s): "1514"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5452kb
input:
5 10 20 8 4 5 0 2 2 5 1 8 4 5 0 10 3 5 0 7 1 3 1 1 2 4 1 6 3 5 1 10 3 5 0 4 1 5 1 7 3 4 1 2 2 4 1 8 3 4 0 9 3 5 0 5 2 5 1 9 4 5 0 9 1 2 0 6 1 5 1 8 3 5 0 2 2 4 1 8 3 5 0
output:
28131
result:
ok 1 number(s): "28131"
Test #4:
score: 0
Accepted
time: 16ms
memory: 17904kb
input:
10 100 200 95 5 7 0 7 4 6 1 62 9 10 0 32 5 8 1 31 2 6 1 75 7 9 1 1 4 7 1 18 7 10 1 75 1 8 1 87 6 9 1 44 7 8 1 68 6 9 1 95 4 6 0 34 1 2 1 70 1 6 1 31 5 9 1 15 6 10 1 48 5 8 1 51 3 7 1 39 5 9 1 23 2 3 1 7 8 9 1 84 7 10 1 13 4 9 1 18 3 6 1 59 9 10 0 31 8 10 1 6 7 9 1 76 3 10 1 41 5 6 0 33 3 4 1 96 1 10...
output:
655333622
result:
ok 1 number(s): "655333622"
Test #5:
score: 0
Accepted
time: 26ms
memory: 30364kb
input:
10 200 200 106 9 10 0 93 4 10 1 199 3 7 0 73 2 9 1 105 8 9 0 38 9 10 1 73 8 10 1 153 3 9 1 123 2 5 1 159 7 9 0 154 5 7 1 162 3 7 0 113 1 5 1 131 7 9 1 67 4 6 1 178 6 10 0 157 7 9 0 147 9 10 0 154 7 10 0 123 3 4 1 39 8 10 1 139 2 9 1 191 9 10 0 36 4 5 1 17 2 8 1 124 3 7 1 9 9 10 1 71 9 10 1 181 7 8 0...
output:
552037151
result:
ok 1 number(s): "552037151"
Test #6:
score: 0
Accepted
time: 38ms
memory: 40744kb
input:
10 300 200 252 1 5 0 48 9 10 1 18 9 10 1 233 9 10 0 195 2 9 1 125 2 5 1 263 7 9 1 24 1 6 1 258 2 10 1 272 8 10 1 76 5 7 1 147 1 7 1 93 9 10 1 30 6 9 1 10 1 10 1 56 2 10 1 93 8 9 1 206 6 9 1 65 1 9 1 226 3 5 0 88 7 8 1 151 3 4 1 292 9 10 0 129 2 3 1 292 9 10 0 180 7 10 1 4 5 10 1 10 9 10 1 151 4 7 1 ...
output:
4494096
result:
ok 1 number(s): "4494096"
Test #7:
score: 0
Accepted
time: 59ms
memory: 67508kb
input:
10 500 300 210 4 7 1 341 8 9 0 371 2 5 0 21 4 10 1 370 8 9 0 368 1 6 0 395 7 9 0 287 6 10 1 299 3 7 1 379 1 9 1 164 4 10 1 390 7 9 0 455 6 9 0 208 8 10 1 402 3 10 0 112 8 10 1 279 3 10 1 180 7 10 1 456 2 6 0 121 5 6 1 312 5 7 0 335 8 10 0 318 2 10 1 497 8 10 0 108 8 9 0 247 3 6 1 155 5 6 1 308 1 2 0...
output:
705403853
result:
ok 1 number(s): "705403853"
Test #8:
score: 0
Accepted
time: 251ms
memory: 67444kb
input:
12 500 300 115 3 10 1 152 10 12 1 89 8 12 1 276 4 7 0 467 6 7 0 405 5 9 0 189 4 9 1 197 1 3 1 341 7 8 0 67 7 8 1 266 2 6 1 78 8 12 1 317 11 12 0 417 8 10 0 380 2 8 0 255 2 5 1 80 7 9 1 317 5 11 1 470 5 9 0 373 3 4 0 413 4 10 0 393 9 12 0 362 8 10 1 42 7 12 1 486 3 5 0 229 1 5 0 224 6 7 0 55 3 10 1 4...
output:
378086467
result:
ok 1 number(s): "378086467"
Test #9:
score: 0
Accepted
time: 312ms
memory: 55724kb
input:
12 500 500 54 11 12 1 325 10 11 0 83 2 3 1 148 3 10 1 165 3 11 1 16 11 12 1 363 8 10 1 78 11 12 1 258 4 12 1 237 8 11 1 403 2 10 1 354 1 9 1 234 4 7 1 454 9 11 0 160 11 12 1 393 1 3 0 375 9 11 0 494 1 3 0 200 6 12 1 414 11 12 0 217 9 10 0 92 5 9 1 172 5 6 1 110 8 12 1 339 4 12 1 429 2 4 0 29 10 11 1...
output:
948753642
result:
ok 1 number(s): "948753642"
Test #10:
score: -100
Time Limit Exceeded
input:
14 500 500 362 4 12 1 225 5 9 1 428 5 9 1 101 8 10 1 488 5 9 0 249 11 14 1 232 2 6 1 220 4 10 1 20 7 13 1 154 4 13 1 480 8 14 0 9 2 4 1 201 7 10 1 174 10 11 0 169 13 14 0 256 10 12 1 403 11 13 0 492 10 14 0 167 6 12 1 123 11 13 1 471 9 10 0 77 5 9 1 51 6 10 1 411 11 14 1 422 11 13 0 7 1 7 1 284 5 11...