結果

問題 No.1328 alligachi-problem
ユーザー tnakao0123tnakao0123
提出日時 2020-12-25 23:11:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 2,022 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 102,888 KB
実行使用メモリ 6,012 KB
最終ジャッジ日時 2023-10-23 23:31:48
合計ジャッジ時間 8,471 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 81 ms
5,828 KB
testcase_10 AC 56 ms
5,172 KB
testcase_11 AC 81 ms
5,700 KB
testcase_12 AC 81 ms
5,824 KB
testcase_13 AC 81 ms
5,832 KB
testcase_14 AC 81 ms
5,712 KB
testcase_15 AC 56 ms
5,304 KB
testcase_16 AC 81 ms
5,704 KB
testcase_17 AC 81 ms
5,836 KB
testcase_18 AC 81 ms
5,832 KB
testcase_19 AC 81 ms
5,700 KB
testcase_20 AC 81 ms
5,704 KB
testcase_21 AC 81 ms
5,704 KB
testcase_22 AC 81 ms
5,708 KB
testcase_23 AC 56 ms
5,172 KB
testcase_24 AC 56 ms
5,688 KB
testcase_25 AC 56 ms
5,764 KB
testcase_26 AC 70 ms
6,012 KB
testcase_27 AC 70 ms
6,012 KB
権限があれば一括ダウンロードができます

ソースコード

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 pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii wcs[2][2];
int cis[2][2], as[MAX_N];

/* subroutines */

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

inline int wcsize(int c, int x, int y) {
  vpii &wc = wcs[c][x];
  int k = 0;
  for (int i = cis[c][x];
       k < 2 && i < wc.size() && wc[i].first == y;
       i++, k++);
  return k;
}

inline int wcget(int c, int x) { return wcs[c][x][cis[c][x]++].second; }

/* 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].push_back(pii(y, i));
  }

  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      sort(wcs[i][j].begin(), wcs[i][j].end());

  for (int i = 0, rn = 0, bn = 0; i < n; i++) {
    if (wcsize(R, R, rn) == 1 && wcsize(B, R, rn) == 0)
      as[i] = wcget(R, R), rn++;
    else if (wcsize(B, B, bn) == 1 && wcsize(R, B, bn) == 0)
      as[i] = wcget(B, B), bn++;
    else if (wcsize(R, B, bn) > 0 &&
	     wcsize(R, R, rn) == 0 && wcsize(B, R, rn) == 0)
      as[i] = wcget(R, B), rn++;
    else if (wcsize(B, R, rn) > 0 &&
	     wcsize(R, B, bn) == 0 && wcsize(B, B, bn) == 0)
      as[i] = wcget(B, R), 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