結果

問題 No.1328 alligachi-problem
ユーザー tnakao0123tnakao0123
提出日時 2020-12-25 19:12:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,741 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 100,452 KB
実行使用メモリ 542,220 KB
最終ジャッジ日時 2023-10-23 18:49:08
合計ジャッジ時間 24,413 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1328.cc:  No.1328 alligachi-problem - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const char ccs[] = "RB";
enum { R = 0, B = 1 };

/* typedef */

typedef queue<int> qi;

/* global variables */

qi wcs[2][2][MAX_N];
int as[MAX_N];

/* subroutines */

inline int c2i(char c) {
  return (c == 'R') ? R : (c == 'B') ? B : -1;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    char s[8], t[8];
    int y;
    scanf("%s%s%d", s, t, &y);
    int c = c2i(s[0]), x = c2i(t[0]);
    wcs[c][x][y].push(i);
  }

  for (int i = 0, rn = 0, bn = 0; i < n; i++) {
    if (wcs[R][R][rn].size() == 1 && wcs[B][R][rn].empty())
      as[i] = wcs[R][R][rn].front(), wcs[R][R][rn].pop(), rn++;
    else if (wcs[B][B][bn].size() == 1 && wcs[R][B][bn].empty())
      as[i] = wcs[B][B][bn].front(), wcs[B][B][bn].pop(), bn++;
    else if (! wcs[R][B][bn].empty() &&
	     wcs[R][R][rn].empty() && wcs[B][R][rn].empty())
      as[i] = wcs[R][B][bn].front(), wcs[R][B][bn].pop(), rn++;
    else if (! wcs[B][R][rn].empty() &&
	     wcs[R][B][bn].empty() && wcs[B][B][bn].empty())
      as[i] = wcs[B][R][rn].front(), wcs[B][R][rn].pop(), bn++;
    else {
      puts("No"); return 0;
    }
    //printf("as[%d]=%d\n", i, as[i]);
  }

  puts("Yes");
  for (int i = 0; i < n; i++)
    printf("%d%c", as[i] + 1, (i + 1 < n) ? ' ' : '\n');
  return 0;
}
0