結果

問題 No.307 最近色塗る問題多くない?
ユーザー treeonetreeone
提出日時 2016-05-02 23:22:46
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,172 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 161,396 KB
実行使用メモリ 14,016 KB
最終ジャッジ日時 2024-04-15 09:28:00
合計ジャッジ時間 17,616 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,648 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 37 ms
6,656 KB
testcase_09 AC 13 ms
5,376 KB
testcase_10 AC 189 ms
5,376 KB
testcase_11 AC 1,348 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 14 ms
5,376 KB
testcase_18 AC 33 ms
5,504 KB
testcase_19 AC 31 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 38 ms
5,376 KB
testcase_22 AC 33 ms
6,528 KB
testcase_23 AC 188 ms
6,944 KB
testcase_24 AC 72 ms
5,760 KB
testcase_25 AC 112 ms
7,552 KB
testcase_26 AC 190 ms
7,808 KB
testcase_27 AC 742 ms
5,376 KB
testcase_28 AC 752 ms
7,424 KB
testcase_29 AC 10 ms
5,376 KB
testcase_30 AC 2,024 ms
7,936 KB
testcase_31 AC 1,853 ms
5,376 KB
testcase_32 AC 1,845 ms
5,376 KB
testcase_33 AC 14 ms
5,376 KB
testcase_34 TLE -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:25: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type*’ {aka ‘long long int*’} [-Wformat=]
   39 |                 scanf("%d %d %d",&r[i],&c[i],&x[i]);
      |                        ~^
      |                         |
      |                         int*
      |                        %lld
main.cpp:39:28: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type*’ {aka ‘long long int*’} [-Wformat=]
   39 |                 scanf("%d %d %d",&r[i],&c[i],&x[i]);
      |                           ~^
      |                            |
      |                            int*
      |                           %lld
main.cpp:39:31: warning: format ‘%d’ expects argument of type ‘int*’, but argument 4 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type*’ {aka ‘long long int*’} [-Wformat=]
   39 |                 scanf("%d %d %d",&r[i],&c[i],&x[i]);
      |                              ~^
      |                               |
      |                               int*
      |                              %lld
main.cpp:39:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |                 scanf("%d %d %d",&r[i],&c[i],&x[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int a[210][210];
int dy[4]={1,-1,0,0};
int dx[4]={0,0,1,-1};
int h,w,q;
bool f[210][210];

void dfs(int r,int c,int color,int x){
	f[r][c]=true;
	a[r][c]=x;
	rep(i,0,4){
		int ny=r+dy[i];
		int nx=c+dx[i];
		if(0<=ny && ny<h && 0<=nx && nx<w && a[ny][nx]==color && f[ny][nx]==false){
			dfs(ny,nx,color,x);
		}
	}
	return;
}

signed main(){
	cin>>h>>w;
	rep(i,0,h) rep(j,0,w) cin>>a[i][j];
	cin>>q;
	vi r(q),c(q),x(q);
	rep(i,0,q){
		scanf("%d %d %d",&r[i],&c[i],&x[i]);
	}
	bool g=false;
	rep(i,0,q){
		r[i]--; c[i]--;
		int color=a[r[i]][c[i]];
		rep(k,0,h) rep(j,0,w) f[k][j]=false;
		dfs(r[i],c[i],color,x[i]);
		int sum=0;
		rep(k,0,h) rep(j,0,w) if(a[k][j]==a[0][0]) sum++;
		if(sum==h*w){
			g=true; break;
		}
	}
	if(g){
		rep(i,0,h) rep(j,0,w) a[i][j]=x[q-1];
	}
	rep(i,0,h){
		rep(j,0,w){
			cout<<(j?" ":"")<<a[i][j];
		}
		cout<<endl;
	}
}
0