結果

問題 No.1123 Afforestation
ユーザー catuppercatupper
提出日時 2020-07-22 23:08:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,529 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 94,416 KB
実行使用メモリ 25,932 KB
最終ジャッジ日時 2023-09-05 03:53:40
合計ジャッジ時間 18,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,480 KB
testcase_04 AC 9 ms
7,484 KB
testcase_05 AC 83 ms
14,628 KB
testcase_06 AC 442 ms
25,676 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 3 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 46 ms
10,056 KB
testcase_13 AC 507 ms
25,916 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 11 ms
7,536 KB
testcase_20 AC 111 ms
14,576 KB
testcase_21 AC 504 ms
25,804 KB
testcase_22 AC 507 ms
25,764 KB
testcase_23 AC 509 ms
25,808 KB
testcase_24 AC 510 ms
25,832 KB
testcase_25 AC 491 ms
25,868 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 3 ms
4,404 KB
testcase_28 AC 332 ms
25,752 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 337 ms
25,772 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 3 ms
4,408 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 6 ms
5,204 KB
testcase_43 AC 12 ms
7,436 KB
testcase_44 AC 20 ms
7,608 KB
testcase_45 AC 21 ms
7,716 KB
testcase_46 AC 26 ms
9,720 KB
testcase_47 AC 31 ms
9,752 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 4 ms
4,376 KB
testcase_51 AC 3 ms
4,380 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 3 ms
4,404 KB
testcase_57 WA -
testcase_58 AC 7 ms
5,428 KB
testcase_59 AC 11 ms
7,784 KB
testcase_60 AC 23 ms
7,600 KB
testcase_61 AC 24 ms
7,640 KB
testcase_62 AC 25 ms
9,756 KB
testcase_63 AC 28 ms
9,700 KB
testcase_64 WA -
testcase_65 WA -
testcase_66 AC 2 ms
4,384 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 4 ms
4,400 KB
testcase_69 AC 5 ms
4,684 KB
testcase_70 WA -
testcase_71 AC 13 ms
7,540 KB
testcase_72 AC 1 ms
4,376 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 2 ms
4,376 KB
testcase_75 AC 1 ms
4,376 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 1 ms
4,380 KB
testcase_78 AC 2 ms
4,376 KB
testcase_79 AC 2 ms
4,376 KB
testcase_80 AC 1 ms
4,376 KB
testcase_81 AC 2 ms
4,380 KB
testcase_82 AC 1 ms
4,380 KB
testcase_83 WA -
testcase_84 AC 178 ms
25,776 KB
testcase_85 AC 190 ms
25,932 KB
testcase_86 AC 1 ms
4,376 KB
testcase_87 AC 2 ms
4,380 KB
testcase_88 AC 114 ms
17,804 KB
testcase_89 AC 114 ms
17,588 KB
testcase_90 AC 2 ms
4,376 KB
testcase_91 AC 2 ms
4,380 KB
testcase_92 AC 1 ms
4,376 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]++;
        }
    }

    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();
        }
    }
    
    cout << "Yay!" << endl;
    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