結果

問題 No.5002 stick xor
ユーザー kimiyuki
提出日時 2018-05-26 00:06:01
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 1,000 ms
コード長 2,774 bytes
コンパイル時間 5,045 ms
実行使用メモリ 1,536 KB
スコア 33,167
最終ジャッジ日時 2018-05-26 00:06:08
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

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; }
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) {
reverse(ALL(lookup[len])); // for better visualization
for (int i : lookup[len]) {
int highscore = -1;
REP (y, n - len) REP (x, n) {
int score = 0;
REP (dy, len) score += a[y + dy][x];
if (highscore < score) {
highscore = score;
result[i] = make_tuple(y, x, false);
}
}
int y, x; tie(y, x, ignore) = result[i];
REP (dy, len) {
auto && p = a[y + dy][x];
p = not p;
}
}
}
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;
int nx = x;
(is_vertical ? nx : ny) += l[i] - 1;
cout << y + 1 << ' ' << x + 1 << ' ' << ny + 1 << ' ' << nx + 1 << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0