結果

問題 No.640 76本のトロンボーン
ユーザー parukiparuki
提出日時 2018-01-27 00:26:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,995 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 171,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:00:22
合計ジャッジ時間 2,224 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

/*
まず横向きに置く方法を決める。

横向きがすべて決まったとき、まだ縦に置ける場合は
1. 横向きが1行目にしかない
2. 横向きがN行目にしかない
3. 横向きがすべて左に寄っている
4. 横向きがすべて右に寄っている
5. 横向きが1行目とN行目に置いてあってかつ縦に一個ずれている場合
整理すると
①1行目またはN行目にたかだか1個ずつ存在する
②左右のどちらか一方に寄っている
このとき、残りの縦方向は貪欲に決めればいい。

これ以外の場合は縦に置けないので全て横に置くことになり、貪欲
*/

int N, ans;
bool a[75][75], b[75][75], c[75][75];

int put(int i, int j, int di, int dj) {
    int ni = i + di*(N - 1);
    int nj = j + dj*(N - 1);
    if (ni > N || nj > N)RT 0;
    rep(k, N - 1) {
        int ii = i + di*k;
        int jj = j + dj*k;
        if (a[ii][jj])RT 0;
    }
    rep(k, N - 1) {
        int ii = i + di*k;
        int jj = j + dj*k;
        a[ii][jj] = true;
    }
    RT 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    cin >> N;
    vector<string> S(N);
    rep(i, N) {
        cin >> S[i];
        rep(j, N)if (S[i][j] == '#')c[i][j] = true;
    }

    // すべて左に置く
    // またはすべて右に置く
    rep(sx, 2) {
        memcpy(a, c, sizeof a);
        int val = 0;
        rep(i, N) {
            // i行目に置く
            val += put(i, sx, 0, 1);
        }
        // 縦はおけるだけ置く
        rep(i, 2)rep(j, N)val += put(i, j, 1, 0);
        smax(ans, val);
    }

    vector<pii> sp{ {0, 0}, { 0,1 }, { N - 1,0 }, { N - 1,1 }};
    // 上または下だけに置く
    rep(S, 1 << 4) {
        memcpy(a, c, sizeof a);
        int val = 0;
        rep(i,4)if(S>>i&1)val += put(sp[i].first, sp[i].second, 0, 1);
        // 縦はおけるだけ置く
        rep(i, N)rep(j, N)val += put(i, j, 1, 0);
        smax(ans, val);
    }

    // 横向きだけ置く
    {
        memcpy(a, c, sizeof a);
        int val = 0;
        // 横におけるだけ
        rep(i, N)rep(j, N) {
            val += put(i, j, 0, 1);
        }
        smax(ans, val);
    }

    cout << ans << endl;
}
0