이 제출은 이전 버전의 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 n;
vi A;
void solve()
{
memset(dp,-1,sizeof(dp));
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 --)
{
//cout << "here " << i << ' ' << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << endl;
unordered_set<int> u;
unordered_set<int> v;
if(x1 != 0)
u.insert(x1);
if(x2 != 0)
u.insert(x2);
if(y1 != 0)
v.insert(y1);
if(y2 != 0)
v.insert(y2);
u.insert(A[i]);
v.insert(A[i]);
if(i == n-1)
{
dp[(i&1)][x1][x2][y1][y2] = max(u.size(),v.size());
continue;
}
int x = dp[1-(i&1)][x2][A[i]][y1][y2] + u.size();
int y = dp[1-(i&1)][x1][x2][y2][A[i]] + v.size();
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... |