結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-11-27 07:12:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 790 ms / 4,000 ms |
| コード長 | 1,700 bytes |
| コンパイル時間 | 804 ms |
| コンパイル使用メモリ | 74,484 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 21:47:44 |
| 合計ジャッジ時間 | 7,366 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main_()’:
main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d%d", &h,&w);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:19:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%d", &a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
main.cpp:52:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
52 | scanf("%d%d%d", &r,&c,&x);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <string>
#include <algorithm>
using namespace std;
typedef bitset<62750> bits;
int h,w;
int main_(){
scanf("%d%d", &h,&w);
vector<vector<int>> a(h, vector<int>(w));
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
scanf("%d", &a[i][j]);
}
}
bits s;
bits filter;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
int pos = i*(w+1) + j;
if(a[i][j]) s.set(pos);
filter.set(pos);
}
}
auto dbg = [&](){
string tmp = s.to_string();
reverse(tmp.begin(), tmp.end());
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
printf("%c%s", tmp[i*(w+1)+j], (j==w-1)?"\n":" ");
}
}
puts("");
};
bool filled = false;
int last = -1;
int q;
scanf("%d", &q);
while(q--){
int r,c,x;
scanf("%d%d%d", &r,&c,&x);
r--; c--;
last = x;
if(filled) continue;
if(x == s[r*(w+1)+c]) continue;
bits z;
z.set(r*(w+1) + c);
if(x==0){
while(1){
bits last = z;
z |= ((z<<1) | (z>>1) | (z<<(w+1)) | (z>>(w+1))) & s;
if(z == last) break;
}
}else{
bits ns = (~s & filter);
while(1){
bits last = z;
z |= ((z<<1) | (z>>1) | (z<<(w+1)) | (z>>(w+1))) & ns;
if(z == last) break;
}
}
s ^= z;
int cnt = s.count();
filled = cnt == 0 || cnt == h*w;
//dbg();
}
if(filled){
s.reset();
if(last == 1) s.flip();
}
string tmp = s.to_string();
reverse(tmp.begin(), tmp.end());
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
printf("%c%s", tmp[i*(w+1)+j], (j==w-1)?"\n":" ");
}
}
return 0;
}
int main(){
auto start = clock();
main_();
cerr << clock() - start << " [ms]" << endl;
return 0;
}
koyumeishi