# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111632 | onlk97 | 건물 4 (JOI20_building4) | C++14 | 199 ms | 45648 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using pii=pair <int,int>;
pii merge(pii a,pii b){
if (a.x==-1) return b;
if (b.x==-1) return a;
return {min(a.x,b.x),max(a.y,b.y)};
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin>>n;
int a[2][2*n+1];
for (int i=0; i<2; i++){
for (int j=1; j<=2*n; j++) cin>>a[i][j];
}
pii dp[2][2*n+1];
for (int i=0; i<2; i++){
for (int j=1; j<=2*n; j++) dp[i][j]={-1,-1};
}
dp[0][1]={0,0}; dp[1][1]={1,1};
for (int j=2; j<=2*n; j++){
for (int i=0; i<2; i++){
for (int k=0; k<2; k++){
if (a[k][j-1]<=a[i][j]){
if (dp[k][j-1].x!=-1) dp[i][j]=merge(dp[i][j],{dp[k][j-1].x+i,dp[k][j-1].y+i});
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |