結果

問題 No.5002 stick xor
ユーザー kimiyukikimiyuki
提出日時 2018-05-26 00:20:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 1,000 ms
コード長 3,531 bytes
コンパイル時間 5,454 ms
実行使用メモリ 1,544 KB
スコア 39,587
最終ジャッジ日時 2018-05-26 00:20:33
ジャッジサーバーID
(参考情報)
judge7 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
1,540 KB
testcase_01 AC 66 ms
1,544 KB
testcase_02 AC 67 ms
1,540 KB
testcase_03 AC 69 ms
1,536 KB
testcase_04 AC 68 ms
1,536 KB
testcase_05 AC 74 ms
1,536 KB
testcase_06 AC 67 ms
1,540 KB
testcase_07 AC 64 ms
1,540 KB
testcase_08 AC 56 ms
1,540 KB
testcase_09 AC 57 ms
1,536 KB
testcase_10 AC 59 ms
1,540 KB
testcase_11 AC 58 ms
1,536 KB
testcase_12 AC 59 ms
1,544 KB
testcase_13 AC 57 ms
1,536 KB
testcase_14 AC 62 ms
1,540 KB
testcase_15 AC 57 ms
1,540 KB
testcase_16 AC 57 ms
1,536 KB
testcase_17 AC 58 ms
1,544 KB
testcase_18 AC 57 ms
1,540 KB
testcase_19 AC 56 ms
1,544 KB
testcase_20 AC 56 ms
1,540 KB
testcase_21 AC 58 ms
1,536 KB
testcase_22 AC 56 ms
1,540 KB
testcase_23 AC 57 ms
1,540 KB
testcase_24 AC 57 ms
1,544 KB
testcase_25 AC 55 ms
1,540 KB
testcase_26 AC 65 ms
1,540 KB
testcase_27 AC 66 ms
1,536 KB
testcase_28 AC 79 ms
1,540 KB
testcase_29 AC 56 ms
1,544 KB
testcase_30 AC 56 ms
1,536 KB
testcase_31 AC 60 ms
1,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= int(m); -- (i))
#define ALL(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T> inline void chmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, int(xs.size()) - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

int count_black(int y, int x, bool is_vertical, int len, vector<vector<bool> > const & a) {
    if (is_vertical) {
        int cnt = 0;
        REP (i, len) cnt += a[y + i][x];
        return cnt;
    } else {
        return count(a[y].begin() + x, a[y].begin() + (x + len), true);
    }
}

void apply_rect(int y, int x, bool is_vertical, int len, vector<vector<bool> > & a) {
    REP (i, len) {
        int ny = y + (is_vertical ? i : 0);
        int nx = x + (is_vertical ? 0 : i);
        auto && p = a[ny][nx];
        p = not p;
    }
}

vector<tuple<int, int, bool> > solve(int n, int k, vector<int> const & l, vector<vector<bool> > a) {
    vector<vector<int> > lookup(n + 1);
    REP (i, k) lookup[l[i]].push_back(i);
    vector<tuple<int, int, bool> > result(k);
    REP_R (len, n + 1) {
        for (int i : lookup[len]) {
            int highscore = -1;
            REP (y, n) REP (x, n) REP (is_vertical, 2) {
                if (    is_vertical and y + len > n) continue;
                if (not is_vertical and x + len > n) continue;
                int score = count_black(y, x, is_vertical, l[i], a);
                if (highscore < score) {
                    highscore = score;
                    result[i] = make_tuple(y, x, is_vertical);
                }
            }
            assert (highscore != -1);
            int y, x; bool is_vertical; tie(y, x, is_vertical) = result[i];
            apply_rect(y, x, is_vertical, l[i], a);
        }
    }
    int white = 0;
    REP (y, n) white += count(ALL(a[y]), false);
    cerr << "white = " << white << " / " << n * n << endl;
    return result;
}

int main() {
    // input
    int n, k; cin >> n >> k;
    vector<int> l(k);
    REP (i, k) cin >> l[i];
    auto a = vectors(n, n, bool());
    REP (y, n) REP (x, n) {
        char c; cin >> c;
        a[y][x] = c - '0';
    }

    // solve
    vector<tuple<int, int, bool> > result = solve(n, k, l, a);

    // output
    REP (i, k) {
        int y, x; bool is_vertical; tie(y, x, is_vertical) = result[i];
        int ny = y + (is_vertical ? l[i] - 1 : 0);
        int nx = x + (is_vertical ? 0 : l[i] - 1);
        cout << y + 1 << ' ' << x + 1 << ' ' << ny + 1 << ' ' << nx + 1 << endl;
    }
    return 0;
}
0