結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー KKT89KKT89
提出日時 2021-02-19 22:43:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,990 bytes
コンパイル時間 2,001 ms
コンパイル使用メモリ 200,636 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-15 03:41:08
合計ジャッジ時間 25,810 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,352 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,352 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,352 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,348 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,352 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,348 KB
testcase_29 WA -
testcase_30 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr ll mod=1e9+7;

ll mod_pow(ll x,ll n){
	x%=mod;
	ll res=1;
	while(n>0){
		if(n&1LL)res=res*x%mod;
		x=x*x%mod; n>>=1LL;
	}
	return res;
}

void solve(int h,int w,int k){
	if(h==1){
		if(w==1){
			if(k<=9) printf("%d\n",k);
			else printf("-1\n");
			return;
		}
		if(k<=18 and w%3==2){
			for(int i=0;i<w;i++){
				if(i%3==0)printf("%d",min(k,9));
				else if(i%3==1)printf("%d",k-min(k,9));
				else printf("0");
			}
			printf("\n");
			return;
		}
		printf("-1\n");
		return;
	}
	if(w==1){
		if(k<=18 and h%3==2){
			for(int i=0;i<h;i++){
				if(i%3==0)printf("%d\n",min(k,9));
				else if(i%3==1)printf("%d\n",k-min(k,9));
				else printf("0\n");
			}
			return;
		}
		return;
	}
	if(h==2 and w==2){
		if(k<=36){
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					printf("%d",min(k,9));
					k-=min(k,9);
				}
				printf("\n");
			}
		}
		else printf("-1\n");
		return;
	}
	if(h==2){
		if(w%3==2 and k<=36){
			vector<int> v(4);
			for(int i=0;i<4;i++){
				v[i]=min(k,9);
				k-=v[i];
			}
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					if(i==0){
						if(j%3==0)printf("%d",v[0]);
						else if(j%3==1)printf("%d",v[1]);
						else printf("0");
					}
					else{
						if(j%3==0)printf("%d",v[2]);
						else if(j%3==1)printf("%d",v[3]);
						else printf("0");
					}
				}
				printf("\n");
			}
		}
		else printf("-1\n");
		return;
	}
	if(w==2){
		if(h%3==2 and k<=36){
			vector<int> v(4);
			for(int i=0;i<4;i++){
				v[i]=min(k,9);
				k-=v[i];
			}
			for(int i=0;i<h;i++){
				if(i%3==0){
					printf("%d%d\n",v[0],v[1]);
				}
				else if(i%3==1){
					printf("%d%d\n",v[2],v[3]);
				}
				else printf("00\n");
			}
		}
		else printf("-1\n");
		return;
	}
	if(h%3==2 and w%3==2){
		assert(0);
	}
	else printf("-1\n");
	// assert(0);
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int h,w,k; cin >> w >> h >> k;
	solve(h,w,k);
}
0