문제 링크: https://www.acmicpc.net/problem/14453
14453번: Hoof, Paper, Scissors (Silver)
You have probably heard of the game "Rock, Paper, Scissors". The cows like to play a similar game they call "Hoof, Paper, Scissors". The rules of "Hoof, Paper, Scissors" are simple. Two cows play against each-other. They both count to three and then each s
www.acmicpc.net
Prefix Sum
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <bits/stdc++.h>
using namespace std;
int n, a[100001][3];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
char c;
cin >> c;
for(int j = 0; j < 3; j++) {
a[i][j] = a[i - 1][j];
}
if(c == 'P') a[i][0] = a[i - 1][0] + 1;
else if(c == 'H') a[i][1] = a[i - 1][1] + 1;
else a[i][2] = a[i - 1][2] + 1;
}
int ans = 0;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
for(int k = 1; k <= n; k++) {
ans = max(ans, a[k][i] + a[n][j] - a[k][j]);
}
}
}
cout << ans << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Silver' 카테고리의 다른 글
백준 14464 소가 길을 건너간 이유 4 (USACO February 2017 Silver 1번) (0) | 2020.04.19 |
---|---|
백준 14454 Secret Cow Code (USACO January 2017 Silver 3번) (0) | 2020.04.10 |
백준 14452 Cow Dance Show (USACO January 2017 Silver 1번) (0) | 2020.04.03 |
백준 14172 Moocast (USACO December 2016 Silver 3번) (0) | 2020.04.03 |
백준 14171 Cities and States (USACO December 2016 Silver 2번) (0) | 2020.04.02 |