結果
問題 | No.5002 stick xor |
ユーザー | ミドリムシ |
提出日時 | 2018-05-25 22:40:54 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 9 ms / 1,000 ms |
コード長 | 4,282 bytes |
コンパイル時間 | 1,824 ms |
実行使用メモリ | 1,560 KB |
スコア | 543 |
最終ジャッジ日時 | 2018-05-25 22:40:58 |
ジャッジサーバーID (参考情報) |
judge9 / |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
1,552 KB |
testcase_01 | AC | 8 ms
1,556 KB |
testcase_02 | AC | 8 ms
1,556 KB |
testcase_03 | AC | 8 ms
1,556 KB |
testcase_04 | AC | 8 ms
1,556 KB |
testcase_05 | AC | 9 ms
1,556 KB |
testcase_06 | AC | 8 ms
1,556 KB |
testcase_07 | AC | 9 ms
1,552 KB |
testcase_08 | AC | 8 ms
1,560 KB |
testcase_09 | AC | 7 ms
1,552 KB |
testcase_10 | AC | 8 ms
1,556 KB |
testcase_11 | AC | 8 ms
1,556 KB |
testcase_12 | AC | 8 ms
1,556 KB |
testcase_13 | AC | 8 ms
1,552 KB |
testcase_14 | AC | 8 ms
1,552 KB |
testcase_15 | AC | 8 ms
1,560 KB |
testcase_16 | AC | 8 ms
1,560 KB |
testcase_17 | AC | 8 ms
1,556 KB |
testcase_18 | AC | 8 ms
1,556 KB |
testcase_19 | AC | 8 ms
1,552 KB |
testcase_20 | AC | 8 ms
1,552 KB |
testcase_21 | AC | 8 ms
1,556 KB |
testcase_22 | AC | 8 ms
1,552 KB |
testcase_23 | AC | 9 ms
1,556 KB |
testcase_24 | AC | 8 ms
1,552 KB |
testcase_25 | AC | 8 ms
1,560 KB |
testcase_26 | AC | 8 ms
1,548 KB |
testcase_27 | AC | 8 ms
1,556 KB |
testcase_28 | AC | 8 ms
1,560 KB |
testcase_29 | AC | 8 ms
1,560 KB |
testcase_30 | AC | 7 ms
1,560 KB |
testcase_31 | AC | 8 ms
1,556 KB |
ソースコード
#include <iostream> #include <algorithm> #include <vector> using namespace std; template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; } template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; } template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; } int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; } long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }} struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); } template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; } long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} #define mod long(1e9 + 7) #define all(x) (x).begin(), (x).end() #define bitcount(n) __builtin_popcountl(long(n)) struct range{ int y1, x1, y2, x2; }; template< class T > struct CumulativeSum2D { vector< vector< T > > data; CumulativeSum2D(int W, int H) : data(W + 1, vector< int >(H + 1, 0)) {} void add(int x, int y, int z) { ++x, ++y; if(x >= data.size() || y >= data[0].size()) return; data[x][y] += z; } void build() { for(int i = 1; i < data.size(); i++) { for(int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } T query(int sx, int sy, int gx, int gy) { return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]); } }; inline int one(int condition){ if(condition){ return 1; }else{ return 1; } } int main(){ int N, K; cin >> N >> K; int L[K]; for(int i = 0; i < K; i++){ cin >> L[i]; } int space[N][N]; for(int i = 0; i < N; i++){ string space_string; cin >> space_string; for(int j = 0; j < N; j++){ space[i][j] = (space_string[j] == '1'); } } CumulativeSum2D<int> cumulative_sum_space(N, N); for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ cumulative_sum_space.add(i, j, space[i][j]); } } cumulative_sum_space.build(); range ans[K]; for(int i = 0; i < K; i++){ range this_ans = {0, 0, 0, 0}; int this_ans_ans = -1e9; for(int j = 0; j < N; j++){ for(int k = 0; k <= N - L[i]; k++){ if(this_ans_ans < cumulative_sum_space.query(j, k, j + 1, k + L[i])){ this_ans_ans = cumulative_sum_space.query(j, k, j + 1, k + L[i]); this_ans = {j, k, j + 1, k + L[i]}; } if(this_ans_ans < cumulative_sum_space.query(k, j, k + L[i], j + 1)){ this_ans_ans = cumulative_sum_space.query(k, j, k + L[i], j + 1); this_ans = {k, j, k + L[i], j + 1}; } } } for(int j = this_ans.y1; j < this_ans.y2; j++){ for(int k = this_ans.x1; k < this_ans.x2; k++){ space[j][k] ^= 1; cumulative_sum_space.add(j, k, one(space[j][k])); } } ans[i] = this_ans; } for(int i = 0; i < K; i++){ cout << ans[i].y1 + 1 << " " << ans[i].x1 + 1 << " " << ans[i].y2 << " " << ans[i].x2 << endl; } }