結果

問題 No.1397 Analog Graffiti
ユーザー 👑 kmjpkmjp
提出日時 2021-02-18 02:20:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,450 ms / 10,000 ms
コード長 3,178 bytes
コンパイル時間 2,615 ms
コンパイル使用メモリ 220,364 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-12 12:03:54
合計ジャッジ時間 14,487 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1,445 ms
4,376 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 1,450 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1,422 ms
4,372 KB
testcase_12 AC 273 ms
4,376 KB
testcase_13 AC 1,383 ms
4,372 KB
testcase_14 AC 1,383 ms
4,372 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 254 ms
4,376 KB
testcase_17 AC 1,292 ms
4,372 KB
testcase_18 AC 1,328 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 499 ms
4,376 KB
testcase_23 AC 31 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 86 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W,N;
map<vector<pair<int,int>>,ll> from[55],to[55];
const ll mo=998244353;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N;
	int mask;
	FOR(mask,1<<(W+1)) {
		if(mask&&__builtin_popcount(mask)%2==0) {
			vector<pair<int,int>> V;
			FOR(i,7) if(mask&(1<<i)) {
				if(V.empty()||V.back().second!=-1) V.push_back({i,-1});
				else V.back().second=i;
			}
			int num=__builtin_popcount(mask)/2*3;
			from[num][V]++;
		}
	}
	ll ret=0;
	for(y=1;y<=H;y++) {
		FOR(i,55) to[i].clear();
		
		FOR(i,N) {
			FORR2(v,p,from[i]) if(i+v.size()==N) {
				vector<pair<int,int>> V=v;
				vector<int> R;
				sort(ALL(V));
				int pre=V[0].first;
				int ok=1;
				for(j=1;j<V.size();j++) {
					if(V[j].first<pre) ok=0;
					pre=V[j].second;
				}
				if(pre>V[0].second) ok=0;
				if(ok) (ret+=p*(H+1-y))%=mo;
				
			}
			FOR(mask,1<<(W+1)) if(mask&&__builtin_popcount(mask)%2==0) {
				FORR2(v,p,from[i]) {
					int over[7];
					int t[14];
					MINUS(over);
					MINUS(t);
					FORR(w,v) over[w.first]=w.second,over[w.second]=w.first;
					int pre=-1;
					int ng=0;
					int add=0;
					FOR(x,W+1) {
						if(over[x]>=0&&(mask&(1<<x))) {
							if(pre!=-1) ng=1;
							else t[x]=x+W+1,t[x+W+1]=x;
						}
						else if(over[x]>=0) {
							if(pre==-1) pre=x,add++;
							else t[pre]=x,t[x]=pre,pre=-1;
						}
						else if(mask&(1<<x)) {
							add++;
							if(pre==-1) pre=x+W+1,add++;
							else t[pre]=x+W+1,t[x+W+1]=pre,pre=-1;
						}
					}
					if(pre!=-1||ng) continue;
					if(i+add>N) continue;
					/*
					cout<<"!"<<pre<<ng<<mask<<" "<<y<<" "<<i<<" "<<add<<endl;
					FOR(x,W+1) cout<<over[x]<<" ";
					cout<<"|";
					FOR(x,2*(W+1)) cout<<t[x]<<" ";
					cout<<endl;
					*/
					int vis[14]={};
					vector<pair<int,int>> NV;
					FOR(x,W+1) if(vis[x+W+1]==0&&t[x+W+1]>=0) {
						vis[x+W+1]=1;
						NV.push_back({x,0});
						j=t[x+W+1];
						while(j<W+1) {
							vis[j]=1;
							vis[over[j]]=1;
							j=t[over[j]];
						}
						vis[j]=1;
						j-=W+1;
						NV.back().second=j;
					}
					FOR(x,W+1) {
						if(over[x]>=0&&vis[x]==0) ng=1;
					}
					if(ng) continue;
					/*
					cout<<y<<i<<add<<" ";
					FORR(w,v) cout<<w.first<<":"<<w.second<<" ";
					cout<<" -> ";
					FORR(v,NV) cout<<v.first<<":"<<v.second<<" ";
					cout<<p<<endl;
					*/
					(to[i+add][NV]+=p)%=mo;
				}
			}
		}
		swap(from,to);
	}
	cout<<ret%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0