結果

問題 No.2094 Symmetry
ユーザー AFLeartLey0103AFLeartLey0103
提出日時 2022-10-07 22:05:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,485 bytes
コンパイル時間 2,545 ms
コンパイル使用メモリ 170,996 KB
実行使用メモリ 17,188 KB
最終ジャッジ日時 2023-09-03 12:39:36
合計ジャッジ時間 8,934 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 185 ms
16,944 KB
testcase_10 AC 174 ms
16,712 KB
testcase_11 AC 196 ms
16,900 KB
testcase_12 AC 186 ms
16,812 KB
testcase_13 AC 163 ms
16,792 KB
testcase_14 AC 192 ms
16,812 KB
testcase_15 AC 195 ms
16,956 KB
testcase_16 AC 179 ms
17,016 KB
testcase_17 AC 164 ms
16,904 KB
testcase_18 AC 174 ms
16,792 KB
testcase_19 AC 192 ms
16,792 KB
testcase_20 AC 190 ms
16,856 KB
testcase_21 AC 189 ms
16,988 KB
testcase_22 AC 173 ms
16,828 KB
testcase_23 AC 178 ms
16,796 KB
testcase_24 AC 174 ms
17,032 KB
testcase_25 AC 178 ms
16,744 KB
testcase_26 AC 176 ms
16,804 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 129 ms
16,988 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 137 ms
16,980 KB
testcase_31 AC 160 ms
17,188 KB
testcase_32 AC 167 ms
16,836 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 114 ms
17,172 KB
testcase_35 AC 98 ms
16,932 KB
testcase_36 AC 116 ms
16,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 505;
int n,k;
int cnt;
bitset<maxn> vis[maxn];
int gr[maxn][maxn];
class node{
    public:
    int x,y,val;
    node(){}
    node(int _x,int _y,int _val):x(_x),y(_y),val(_val){}
    friend bool operator<(node a,node b){return a.val < b.val;}
};
priority_queue<node> pq;
priority_queue<node> fpq;
int solve1(){
    int localk = cnt;
    if(localk&1)return numeric_limits<long long>::min();
    localk>>=1;
    int fans = 0;
    for(int i = 0;i<=n;++i)vis[i] = 0;
    while(localk){
        localk -= 1;
        auto ed = fpq.top();
        fpq.pop();
        vis[ed.x][ed.y] = 1;
        fans += ed.val;
    }
    return fans+k;
}
int solve2(){
    for(int i = 0;i<=n;++i)vis[i] = 0;
    int localk = cnt;
    int fans = 0;
    while(localk){
        localk-=1;
        auto ed = pq.top();
        pq.pop();
        vis[ed.x][ed.y] = 1;
        fans += ed.val;
    }
    return fans;
}
signed main(){
    cin >> n >> k;
    n *= 2;
    char ch;
    for(int i = 0;i<n;++i)
        for(int j = 0;j<n;++j){
            cin >> ch;
            if(ch == '#')cnt++;
    }
    for(int i = 1;i<=n;++i){
        for(int j = 1;j<=n;++j){
            cin >> gr[i][j];
            pq.push(node(i,j,gr[i][j]));
        }
    }
    for(int i = 1;i<=n;++i){
        for(int j = 1;j<=n>>1;++j){
            fpq.push(node(i,j,gr[i][j] + gr[i][n+1-j]));
        }
    }
    cout << max(solve1(),solve2());
    return 0;
}
0