이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define pb(x) push_back(x)
using namespace std;
const int N = 1e5+5;
const int INF = 1e9+10;
char s[N];
int a[2], b[2];
int arr[N];
int bit[] = {0, 1, 1, 2, 1, 2, 2, 3};
int f(int x, int y, int z){
int mask = 0;
if (x) mask |= (1<<(x-1));
if (y) mask |= (1<<(y-1));
if (z) mask |= (1<<(z-1));
return bit[mask];
}
int main(){
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int n;
scanf("%d", &n);
scanf("%s", s);
for (int i = 0; i < n; i++){
if (s[i] == 'M') arr[i] = 1;
else if(s[i] == 'F') arr[i] = 2;
else arr[i] = 3;
}
int answer = 0;
for (int mask = 0; mask < (1<<n); mask++){
a[0] = a[1] = 0;
b[0] = b[1] = 0;
int cost = 0;
for (int i = 0; i < n; i++){
if (mask>>i&1){
cost += f(a[0], a[1], arr[i]);
a[0] = a[1]; a[1] = arr[i];
}
else{
cost += f(b[0], b[1], arr[i]);
b[0] = b[1]; b[1] = arr[i];
}
}
answer = max(answer, cost);
}
printf("%d\n", answer);
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int main()':
miners.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
miners.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%s", s);
| ~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |