結果

問題 No.2042 RGB Caps
コンテスト
ユーザー vjudge1
提出日時 2025-11-05 16:59:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,527 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 199,528 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-11-05 16:59:59
合計ジャッジ時間 6,617 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:87:14: warning: ‘num’ may be used uninitialized [-Wmaybe-uninitialized]
   87 |         v[a] = num;
main.cpp:57:11: note: ‘num’ was declared here
   57 |       int num;
      |           ^~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  t = 1;

  while (t--)
  {
    int n, k;
    cin >> n >> k;
    string s;

    for (int i = 0; i < n; i++)
    {
      if (i % 3 == 0)
      {
        s = s + 'R';
      }
      if (i % 3 == 1)
      {
        s = s + 'G';
      }
      if (i % 3 == 2)
      {
        s = s + 'B';
      }

    }
    if (n % 3 == 1)
    {
      s = s + 'G';
      s = s + 'B';

    }
    if (n % 3 == 2)
    {

      s += 'B';

    }
    if (n % 3 == 0)
    {
      s = s + 'R';
      s = s + 'G';
      s = s + 'B';

    }
    int flag = 1;
    vector<int>v(n + 1, 0);
    for (int i = 0; i < k; i++)
    {
      int a;
      char c;

      cin >> a >> c;
      int num;
      if (c == 'R')
      {
        num = 1;
      }
      if (c == 'G')
      {
        num = 2;
      }
      if (c == 'B')
      {
        num = 3;
      }



      if (v[a] != 0)
      {

        if (v[a] != num)
        {

          flag = 0;

        }
      }


      else
      {
        v[a] = num;
      }


      if (a % 3 == 1)
      {
        if (c == 'G')
        {
          swap(s[a - 1], s[a]);
        }
        if (c == 'B')
        {
          swap(s[a - 1], s[a + 1]);
        }

      }
      if (a % 3 == 2)
      {
        if (c == 'B')
        {
          swap(s[a - 1], s[a ]);
        }
      }

    }
    if (!flag)
    {
      cout << -1 << endl;
      continue;
    }

    for (int i = 0; i < n; i++)
    {
      cout << s[i];
    }
    cout << endl;



  }


  return 0;
}
0