結果

問題 No.307 最近色塗る問題多くない?
ユーザー naimonon77naimonon77
提出日時 2016-03-07 12:07:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,353 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 164,444 KB
実行使用メモリ 4,560 KB
最終ジャッジ日時 2023-10-24 20:14:27
合計ジャッジ時間 2,928 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 14 ms
4,348 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 20 ms
4,348 KB
testcase_32 AC 19 ms
4,348 KB
testcase_33 WA -
testcase_34 AC 19 ms
4,348 KB
testcase_35 AC 19 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:91:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   91 |   scanf("%d",&H);
      |   ~~~~~^~~~~~~~~
main.cpp:92:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   92 |   scanf("%d",&W);
      |   ~~~~~^~~~~~~~~
main.cpp:95:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   95 |       scanf("%d",&A[i][j]);
      |       ~~~~~^~~~~~~~~~~~~~~
main.cpp:98:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   98 |   scanf("%d",&Q);
      |   ~~~~~^~~~~~~~~
main.cpp:102:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  102 |     scanf("%d %d %d",&R,&C,&X);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:116:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  116 |     scanf("%d %d %d",&R,&C,&X);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#ifdef _MSC_VER
#include "bits\stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <list>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
// #define rep(i,n) REP(i,1,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )

// #define int ll

using namespace std;


bool test = 0;
/* ここからが本編 */
/* pow(x,n)はx^nを返すよ! */
static int A[200][200];
int H,W;
int target_color;
int next_color;
void print_map()
{
  int i,j;
  if(test) puts("---map---");
  for(i=0;i<H;i++) {
    printf("%d",A[i][0]);
    for(j=1;j<W;j++) {
      printf(" %d",A[i][j]);
    }
    puts("");
  }
  if(test) puts("---------");
}

struct Point{
  int R,C;
};

int draw(int R, int C) {
  int i,j;
  queue<Point> q;
  Point start = {R,C};
  int dR[] = { 0, 0,-1, 1};
  int dC[] = { 1,-1, 0, 0};
  int cnt = 0;
  static bool visited[200][205];
  q.push(start);
  while( q.size() ) {
    Point now = q.front(); q.pop();
    visited[now.R][now.C] = true;
    cnt++;
    if(test) {
      printf("A[%d][%d] = %d ",now.R,now.C,A[R][C]);
      printf("target_color = %d\n",target_color);
      printf("R = %d C = %d\n",now.R,now.C);
    }

    A[now.R][now.C] = next_color;
    rep(i,4) {
      Point next;
      next.R = now.R+dR[i];
      next.C = now.C+dC[i];
      if(next.R < 0 || H <= next.R) continue; 
      else if(next.C < 0 || W <= next.C) continue;
      else if( visited[next.R][next.C] ) continue;
      else if(A[next.R][next.C] == target_color) {
        q.push(next);
      }
    }
  }
  return cnt;
}
int main(void)
{
  int i,j,k,l;
  int Q;
  scanf("%d",&H);
  scanf("%d",&W);
  for(i=0;i<H;i++) {
    for(j=0;j<W;j++) {
      scanf("%d",&A[i][j]);
    }
  }
  scanf("%d",&Q);
  int R,C,X;
  bool all_draw = false;
  for(i=0;i<Q;i++) {
    scanf("%d %d %d",&R,&C,&X);
    R--;C--;
    int a = 0;
    if(A[R][C] != X) {
      target_color = A[R][C]; next_color = X;
      a = draw(R,C);
      if(test) print_map();
    }
    if(a == H*W) {
      all_draw = true;
      break;
    }
  }
  for(;i<Q;i++) {
    scanf("%d %d %d",&R,&C,&X);
  }
  if(all_draw) {
    rep(i,H) rep(j,W) A[i][j] = X;
  }
  print_map();
  return 0;
}
0