이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;
#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int nx[4] = {1,-1,0,0}, ny[4] = {0,0,1,-1};
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
ld dist(ld x1, ld y1, ld x2, ld y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}
const int MAX_N = 1e5 + 4;
int dp[2][4][4][4][4];
int memo[4][4][4];
int n;
vi A;
int cost(int a, int b, int c)
{
if(memo[a][b][c] != -1)
return memo[a][b][c];
int dis = (a != b) + (b != c) + (c != a) - (a == 0) - (b == 0) - (c == 0);
return memo[a][b][c] = max(dis,1);
}
void solve()
{
memset(dp,-1,sizeof(dp));
memset(memo,-1,sizeof(memo));
cin >> n;
for(int i = 0; i <n; i ++)
{
char c; cin >> c;
if(c== 'M')
A.pb(1);
else if(c=='F')
A.pb(2);
else
A.pb(3);
}
for(int i = n-1; i >= 0; i --)
{
for(int x1 = 3; x1 >= 0; x1 --)
{
for(int x2 = 3; x2 >= 0; x2 --)
{
for(int y1 = 3; y1 >= 0; y1 --)
{
for(int y2 =3; y2 >= 0; y2 --)
{
if(i == n-1)
{
dp[(i&1)][x1][x2][y1][y2] = max(cost(x1,x2,A[i]),cost(y1,y2,A[i]));
continue;
}
int x = dp[1-(i&1)][x2][A[i]][y1][y2] + cost(x1,x2,A[i]);
int y = dp[1-(i&1)][x1][x2][y2][A[i]] + cost(y1,y2,A[i]);
dp[(i&1)][x1][x2][y1][y2] = max(x,y);
}
}
}
}
}
cout << dp[0][0][0][0][0] ;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tt = 1;
while(tt--)
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
miners.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# | 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... |