結果

問題 No.1123 Afforestation
ユーザー catuppercatupper
提出日時 2020-07-23 00:58:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 517 ms / 2,500 ms
コード長 2,601 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 94,480 KB
実行使用メモリ 25,996 KB
最終ジャッジ日時 2023-09-05 07:32:15
合計ジャッジ時間 15,405 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,436 KB
testcase_04 AC 9 ms
7,488 KB
testcase_05 AC 82 ms
14,592 KB
testcase_06 AC 443 ms
25,772 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 7 ms
5,272 KB
testcase_12 AC 47 ms
9,832 KB
testcase_13 AC 506 ms
25,868 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 11 ms
7,500 KB
testcase_20 AC 112 ms
14,592 KB
testcase_21 AC 506 ms
25,996 KB
testcase_22 AC 506 ms
25,924 KB
testcase_23 AC 508 ms
25,808 KB
testcase_24 AC 517 ms
25,844 KB
testcase_25 AC 489 ms
25,960 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 331 ms
25,716 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 335 ms
25,712 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 7 ms
5,192 KB
testcase_43 AC 13 ms
7,532 KB
testcase_44 AC 21 ms
7,612 KB
testcase_45 AC 21 ms
7,664 KB
testcase_46 AC 26 ms
9,696 KB
testcase_47 AC 32 ms
9,764 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 3 ms
4,376 KB
testcase_51 AC 3 ms
4,384 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 3 ms
4,564 KB
testcase_56 AC 4 ms
4,432 KB
testcase_57 AC 3 ms
4,376 KB
testcase_58 AC 7 ms
5,200 KB
testcase_59 AC 12 ms
7,548 KB
testcase_60 AC 23 ms
7,708 KB
testcase_61 AC 23 ms
7,900 KB
testcase_62 AC 25 ms
9,724 KB
testcase_63 AC 29 ms
9,744 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 3 ms
4,380 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 4 ms
4,376 KB
testcase_69 AC 5 ms
4,980 KB
testcase_70 AC 7 ms
5,196 KB
testcase_71 AC 14 ms
7,528 KB
testcase_72 AC 1 ms
4,380 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 2 ms
4,376 KB
testcase_75 AC 2 ms
4,376 KB
testcase_76 AC 1 ms
4,380 KB
testcase_77 AC 2 ms
4,376 KB
testcase_78 AC 1 ms
4,380 KB
testcase_79 AC 2 ms
4,376 KB
testcase_80 AC 2 ms
4,376 KB
testcase_81 AC 2 ms
4,376 KB
testcase_82 AC 1 ms
4,376 KB
testcase_83 AC 2 ms
4,376 KB
testcase_84 AC 181 ms
25,736 KB
testcase_85 AC 191 ms
25,832 KB
testcase_86 AC 2 ms
4,376 KB
testcase_87 AC 2 ms
4,376 KB
testcase_88 AC 115 ms
17,516 KB
testcase_89 AC 115 ms
17,524 KB
testcase_90 AC 2 ms
4,376 KB
testcase_91 AC 1 ms
4,380 KB
testcase_92 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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++){
        vector<P> bs;
        for(int j = 0;j < w;j++)bs.push_back({b[j], j});
        sort(bs.rbegin(), bs.rend());
        for(int j = 0;j < w;j++){
            if(a[i]>0 && bs[j].first>0){
//                cout << i << " " << bs[j].second << endl;
                a[i]--;
                b[bs[j].second]--;                
                edge[i][bs[j].second+h] = false;
                edge[bs[j].second+h][i] = true;
            }
        }
    }
    
    for(int i = 0;i < h;i++)if(a[i])ng();
    for(int i = 0;i < w;i++)if(b[i])ng();
    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]++;
        }
        else{
            edge[x][y+h] = false;
        }
    }

    for(int i = 0;i < h;i++){
        while(a[i]){
            fill(come, come + 4400, false);
            if(f(i))a[i]--;
            else ng();
        }
    }
    
    cout << "Yay!" << endl;
    for(int i = 0;i < h;i++){
        int cnt = 0;
        for(int j = 0;j < w;j++){
            if(edge[j+h][i]){
                ans[i][j] = 'o';
                cnt++;
            }            
        }

        cout << ans[i] << endl;
    }
    return 0;
}
0