結果
問題 |
No.1924 3 color painting on a line
|
ユーザー |
![]() |
提出日時 | 2022-05-04 22:38:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 813 bytes |
コンパイル時間 | 250 ms |
コンパイル使用メモリ | 41,416 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-04 01:15:59 |
合計ジャッジ時間 | 2,008 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 43 |
ソースコード
/* -*- 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; /* typedef */ /* global variables */ char s[MAX_N + 4]; /* subroutines */ /* main */ int main() { int n; scanf("%d%s", &n, s); int m = 0; for (int i = 0; i < n;) { int j = i; while (i < n && s[j] == s[i]) i++; s[m++] = s[j]; } s[m] = '\0'; n = m; //puts(s); int c = 0; m = 0; for (int i = 0; i < n; i++) { if (m >= 2 && s[m - 2] == s[i]) m -= 2, c++; s[m++] = s[i]; } s[m] = '\0'; n = m; //printf("%s, c=%d\n", s, c); for (int i = 0; i < n; i++) if (i % 3 != 0) s[i] = '\0', c++; //printf("%s, c=%d\n", s, c); printf("%d\n", c + 1); return 0; }