結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー okok
提出日時 2021-02-19 23:50:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 3,153 ms
コード長 13,294 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 92,228 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 00:31:11
合計ジャッジ時間 26,370 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int W, H, X;
    
    cin>>W>>H>>X;
    
    if(X == 0) {
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout<<0;
            }
            cout<<endl;
        }
    } else if(H == 1 && W == 1) {
        if(X > 9) cout<<-1<<endl;
        else cout<<X<<endl;
        
    } else if(H == 1){
        if(X > 18) cout<<-1<<endl;
        else if(W % 3 != 1 && X <= 9){
            
            for(int i = 0; i < W/3; i++){
                if(i) cout<<"";
                cout<<0<<""<<X<<""<<0;
            }
            
            if(W % 3 == 2) cout<<""<<0<<""<<X;
            
            cout<<endl;
        } else if(W % 3 == 2) {
            int A = min(X, 9ll);
            int B = X - A;
            
            cout<<A<<""<<B;
            
            for(int i = 0; i < W/3; i++){
                cout<<""<<0<<""<<A<<""<<B;
            }
            
            cout<<endl;
        } else {
            cout<<-1<<endl;
        }
    } else if(W == 1){
        if(X > 18) cout<<-1<<endl;
        else if(H % 3 != 1 && X <= 9){
            for(int i = 0; i < H/3; i++){
                cout<<0<<endl<<X<<endl<<0<<endl;
            }
            
            if(H % 3 == 2) cout<<0<<endl<<X<<endl;
            
        } else if(H % 3 == 2){
            int A = min(X, 9ll);
            int B = X - A;
            
            cout<<A<<endl<<B<<endl;
            
            for(int i = 0; i < H/3; i++){
                cout<<0<<endl<<A<<endl<<B<<endl;
            }
        } else {
            cout<<-1<<endl;
        }
    } else {
        int A, B, C, D;
        
        if(X > 36) cout<<-1<<endl;
        else if(H % 3 != 1 && W % 3 != 1 && X <= 9) {
            
            for(int i = 0; i < H/3; i++){
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<0<<""<<0<<""<<0;
                }
                if(W%3 == 2) cout<<""<<0<<""<<0;
                    
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<0<<""<<X<<""<<0;
                }
                if(W%3 == 2) cout<<""<<0<<""<<X;
                    
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<0<<""<<0<<""<<0;
                }
                if(W%3 == 2) cout<<""<<0<<""<<0;
                    
                cout<<endl;
            }
            
            if(H % 3 == 2) {
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<0<<""<<0<<""<<0;
                }
                if(W%3 == 2) cout<<""<<0<<""<<0;
                    
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<0<<""<<X<<""<<0;
                }
                if(W%3 == 2) cout<<""<<0<<""<<X;
                    
                cout<<endl;
            }
            
        } else if(H % 3 == 2 && W % 3 == 2){
            A = min(X, 9ll);
            B = min(X - A, 9ll);
            C = min(X - A - B, 9ll);
            D = min(X - A - B - C, 9ll);
            
            cout<<A<<""<<B;
            for(int j = 0; j < W/3; j++){
                cout<<""<<0<<""<<A<<""<<B;
            }
            cout<<endl;
            
            cout<<C<<""<<D;
            for(int j = 0; j < W/3; j++){
                cout<<""<<0<<""<<C<<""<<D;
            }
            cout<<endl;
                
            for(int i = 0; i < H/3; i++){
                cout<<0<<""<<0;
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                cout<<endl;
                
                cout<<A<<""<<B;
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<A<<""<<B;
                }
                cout<<endl;
                
                cout<<C<<""<<D;
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<C<<""<<D;
                }
                cout<<endl;
            }
        } else if(H % 3 != 0 && W % 3 != 0 && X <= 9){
            
            for(int i = 0; i < H/3; i++){
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<X<<""<<0<<""<<0;
                }
                if(W%3 == 1) cout<<""<<X<<"";
                if(W%3 == 2) cout<<""<<X<<""<<0;
                    
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<0<<""<<0<<""<<0;
                }
                if(W%3 == 1) cout<<""<<0<<"";
                if(W%3 == 2) cout<<""<<0<<""<<0;
                    
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<0<<""<<0<<""<<0;
                }
                if(W%3 == 1) cout<<""<<0<<"";
                if(W%3 == 2) cout<<""<<0<<""<<0;
                    
                cout<<endl;
            }
            
            if(H % 3 == 1) {
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<X<<""<<0<<""<<0;
                }
                if(W%3 == 1) cout<<""<<X<<"";
                if(W%3 == 2) cout<<""<<X<<""<<0;
                    
                cout<<endl;
            } else if(H%3 == 2) {
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<X<<""<<0<<""<<0;
                }
                if(W%3 == 1) cout<<""<<X<<"";
                if(W%3 == 2) cout<<""<<X<<""<<0;
                    
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    if(j) cout<<"";
                    cout<<0<<""<<0<<""<<0;
                }
                if(W%3 == 1) cout<<""<<0<<"";
                if(W%3 == 2) cout<<""<<0<<""<<0;
                    
                cout<<endl;
            }
        } else if(W % 3 == 2 && H % 3 != 0 && X <= 18){
            A = min(X, 9ll);
            B = min(X - A, 9ll);
            C = 0;
            D = 0;
            
            for(int i = 0; i < H/3; i++){
                
                cout<<A<<""<<B;
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<A<<""<<B;
                }
                cout<<endl;
                
                cout<<C<<""<<D;
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<C<<""<<D;
                }
                cout<<endl;
                
                cout<<0<<""<<0;
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                cout<<endl;
            }
            
            if(H%3 == 1) {
                cout<<A<<""<<B;
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<A<<""<<B;
                }
                cout<<endl;
                
            }
            
        } else if(W % 3 != 0 && H % 3 == 2 && X <= 18){ 
            A = min(X, 9ll);
            B = 0;
            C = min(X - A, 9ll);
            D = 0;
            
            cout<<A<<"";
            for(int j = 0; j < W/3; j++){
                cout<<""<<B<<""<<0<<""<<A;
            }
            cout<<endl;
            
            cout<<C<<"";
            for(int j = 0; j < W/3; j++){
                cout<<""<<D<<""<<0<<""<<C;
            }
            cout<<endl;
            
            for(int i = 0; i < H/3; i++){
                
                cout<<0<<"";
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                
                cout<<endl;
                
               cout<<A<<"";
                for(int j = 0; j < W/3; j++){
                    cout<<""<<B<<""<<0<<""<<A;
                }
                
                cout<<endl;
                
                cout<<C<<"";
                for(int j = 0; j < W/3; j++){
                    cout<<""<<D<<""<<0<<""<<C;
                }
                
                cout<<endl;
            }
            
        } else if(H % 3 != 0 && W % 3 != 1 && X <= 9) {
            for(int i = 0; i < H/3; i++){
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<X<<""<<0;
                }
                if(W % 3 == 1) cout<<0;
                if(W % 3 == 2) cout<<0<<X;
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                if(W % 3 == 1) cout<<0;
                if(W % 3 == 2) cout<<0<<0;
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                if(W % 3 == 1) cout<<0;
                if(W % 3 == 2) cout<<0<<0;
                cout<<endl;
            }
            
            
            if(H % 3 == 1) {
                 for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<X<<""<<0;
                }
                if(W % 3 == 1) cout<<0;
                if(W % 3 == 2) cout<<0<<X;
                cout<<endl;
            }
            
        } else if(H % 3 != 1 && W % 3 != 0 && X <= 9) {
            for(int i = 0; i < H/3; i++){
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                if(W % 3 == 1) cout<<0;
                if(W % 3 == 2) cout<<0<<0;
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<X<<""<<0<<""<<0;
                }
                if(W % 3 == 1) cout<<X;
                if(W % 3 == 2) cout<<X<<0;
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                if(W % 3 == 1) cout<<0;
                if(W % 3 == 2) cout<<0<<0;
                cout<<endl;
                
                
            }
            
            
            if(H % 3 == 2) {
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                if(W % 3 == 1) cout<<0;
                if(W % 3 == 2) cout<<0<<0;
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<X<<""<<0<<""<<0;
                }
                if(W % 3 == 1) cout<<X;
                if(W % 3 == 2) cout<<X<<0;
                cout<<endl;
                
            }
        } else if(H % 3 == 2 && W % 3 != 1 && X <= 18){
            A = 0;
            B = min(X, 9ll);
            C = 0;
            D = min(X - B, 9ll);
            
            for(int j = 0; j < W/3; j++){
                cout<<""<<A<<""<<B<<""<<0;
            }
            cout<<endl;
            
            for(int j = 0; j < W/3; j++){
                cout<<""<<C<<""<<D<<""<<0;
            }
            cout<<endl;
            
            for(int i = 0; i < H/3; i++){
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                
                cout<<endl;
                
               for(int j = 0; j < W/3; j++){
                    cout<<""<<A<<""<<B<<""<<0;
                }
                cout<<endl;
                
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<C<<""<<D<<""<<0;
                }
                
                cout<<endl;
            }
            
        } else if(W % 3 == 2 && H % 3 != 1 && X <= 18){
            A = 0;
            B = 0;
            C = min(X, 9ll);
            D = min(X - C, 9ll);
            
            for(int i = 0; i < H/3; i++){
               for(int j = 0; j < W/3; j++){
                    cout<<""<<A<<""<<B<<""<<0;
                }
                cout<<""<<A<<""<<B;
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<C<<""<<D<<""<<0;
                }
                cout<<""<<C<<""<<D;
                cout<<endl;
                
                for(int j = 0; j < W/3; j++){
                    cout<<""<<0<<""<<0<<""<<0;
                }
                cout<<""<<0<<""<<0;
                cout<<endl;
            }
        } else {
            cout<<-1<<endl;
        }
    }
	 
	
	return 0;
}
0