結果

問題 No.1123 Afforestation
ユーザー catuppercatupper
提出日時 2020-07-22 22:55:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,233 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 85,724 KB
実行使用メモリ 11,740 KB
最終ジャッジ日時 2023-09-05 03:15:07
合計ジャッジ時間 6,337 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

bool edge[4400][4400];
Int h, w;
Int a[4400], b[4400];
string ans[2200];

void ok(){
    cout << "Yes" << endl;
    exit(0);
}

void ng(){
    cout <<  ":(" << endl;
    exit(0);
}

bool come[4400];

bool f(int s){
    if(come[s])return false;
    come[s] = true;
    if(s >= h && b[s-h]){
        b[s-h]--;
        return true;
    }
    for(int i = 0;i < 4400;i++){
        if(edge[s][i] && f(i)){
            edge[s][i] = false;
            edge[i][s] = true;
            return true;
        }
    }
    return false;
}

int main(){
    cin >> h >> w;
    for(int i = 0;i < h;i++)ans[i] = string(w, '.');
    for(int i = 0;i < h;i++)cin >> a[i];
    for(int i = 0;i < w;i++)cin >> b[i];
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            edge[i][j+h] = true;
        }
    }
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(a[i]>0 && b[j]>0){
                a[i]--;
                b[j]--;                
                edge[i][j+h] = false;
                edge[j+h][i] = true;
            }
        }
    }
    int k;
    cin >> k;
    for(int i = 0;i < k;i++){
        int x, y;
        cin >> x >> y;x--,y--;
        ans[x][y] = 'x';
        if(edge[y+h][x]){
            edge[y+h][x] = false;
            a[x]++;
            b[y]++;
        }
    }

    for(int i = 0;i < h;i++){
        if(a[i] == 0)continue;
        while(a[i]){
            fill(come, come + 4400, false);
            if(f(i))a[i]--;
            else ng();
        }
    }
    for(int i = 0;i < w;i++)if(b[i])ng();

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(edge[j+h][i]){
                ans[i][j] = 'o';
            }            
        }
        cout << ans[i] << endl;
    }
    return 0;
}
0