結果

問題 No.1345 Beautiful BINGO
ユーザー
提出日時 2021-01-16 20:53:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,719 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 94,040 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 02:59:06
合計ジャッジ時間 2,548 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 53
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:54:14: warning: 'n1' may be used uninitialized [-Wmaybe-uninitialized]
   54 |         else if (n1 == 2 * n) {
      |              ^~
main.cpp:41:32: note: 'n1' was declared here
   41 |         int ans1 = 1000000007, n1;
      |                                ^~

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int a[20][20];
int s[40];
int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        s[2 * n] += a[i][i];
        s[2 * n + 1] += a[i][n - i - 1];
        for (int j = 0; j < n; j++) {
            s[i] += a[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            s[n + i] += a[j][i];
        }
    }
    int ans = 0;
    for (int i = 0; i < m; i++) {
        int ans1 = 1000000007, n1;
        for (int j = 0; j < 2 * n + 2; j++) {
            if (ans1 > s[j]) {
                ans1 = s[j];
                n1 = j;
            }
        }
        if (n1 == 2 * n + 1) {
            for (int j = 0; j < n; j++) {
                s[j] -= a[j][n - j - 1];
                s[2 * n - j - 1] -= a[j][n - j - 1];
            }
        }
        else if (n1 == 2 * n) {
            for (int j = 0; j < n; j++) {
                s[j] -= a[j][j];
                s[n + j] -= a[j][j];
            }
        }
        else if (n1 >= n) {
            for (int j = 0; j < n; j++) {
                s[j] -= a[j][n1 - n];
            }
        }
        else {
            for (int j = 0; j < n; j++) {
                s[n + j] -= a[n1 - n][j];
            }
        }
        s[n1] = 1000000007;
        ans += ans1;
    }
    cout << ans << endl;
}
0