結果
問題 | No.5002 stick xor |
ユーザー | kimiyuki |
提出日時 | 2018-05-25 23:35:42 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 1,000 ms |
コード長 | 2,738 bytes |
コンパイル時間 | 5,171 ms |
実行使用メモリ | 1,536 KB |
スコア | 15,635 |
最終ジャッジ日時 | 2018-05-25 23:35:49 |
ジャッジサーバーID (参考情報) |
judge7 / |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#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); REP (len, n + 1) reverse(ALL(lookup[len])); // for better visualization vector<tuple<int, int, bool> > result(k, make_tuple(n - 1, 0, true)); REP (y, n) { REP (x, n) if (a[y][x]) { int len = 1; while (y + len < n and a[y + len][x]) ++ len; while (len and lookup[len].empty()) -- len; if (not len) continue; // use len vertically int i = lookup[len].back(); lookup[len].pop_back(); result[i] = make_tuple(y, x, false); REP3 (y1, y, y + len) { a[y1][x] = not a[y1][x]; } } } 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; }