結果
問題 |
No.1924 3 color painting on a line
|
ユーザー |
![]() |
提出日時 | 2022-05-04 22:19:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 880 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 41,800 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-04 00:55:03 |
合計ジャッジ時間 | 2,393 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 40 |
ソースコード
/* -*- coding: utf-8 -*- * * 1924.cc: No.1924 3 color painting on a line - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 100000; const char ps[] = "RGB"; const int INF = 1 << 30; /* typedef */ /* global variables */ char s[MAX_N + 4]; /* subroutines */ int check(int l, int r) { int c = 0; for (int i = l; i < r;) { int j = i; while (i < r && s[j] == s[i]) i++; c++; } return c / 2 + 1; } /* main */ int main() { int n; scanf("%d%s", &n, s); int mind = INF; for (int ci = 0; ci < 3; ci++) { char p0 = ps[ci]; int d = 1; for (int i = 0; i < n;) { while (i < n && s[i] == p0) i++; if (i >= n) break; int j = i; while (i < n && s[i] != p0) i++; d += check(j, i); } mind = min(mind, d); } printf("%d\n", mind); return 0; }