답안 #146554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146554 2019-08-24T11:13:15 Z brcode Xylophone (JOI18_xylophone) C++14
0 / 100
3 ms 376 KB
#include <iostream>
#include "xylophone.h"
using namespace std;
const int MAXN = 1e5+5;
int pairs[MAXN];
int triplets[MAXN];
int ord[MAXN][4];
int arr[MAXN];
int ans[MAXN];
 
/*int query(int a,int b){
    int mini = 1e9;
    int maxi = 0;
    for(int i=a;i<=b;i++){
        mini = min(mini,arr[i]);
        maxi = max(maxi,arr[i]);
    }
    return maxi-mini;
}
void answer(int i,int a){
    cout<<a<<" ";
}
bool check(int i,int j,int mini,int maxi){
    return query(i,j)==maxi-mini;
}*/
void solve(int n){
    for(int i=1;i<n;i++){
        pairs[i] = query(i,i+1);
       
    }
    for(int i=1;i<n-1;i++){
        triplets[i] = query(i,i+2);
        
    }
    ord[1][1] = 1;
    ord[1][0] = 0;
    for(int i=1;i<n-1;i++){
        if(triplets[i] == pairs[i]+pairs[i+1]){
            ord[i+1][1] = ord[i][1];
            ord[i+1][0] = ord[i][0];
        }else{
            ord[i+1][1] = !ord[i][1];
            ord[i+1][0] = !ord[i][0];
        }
      
    }
    ans[1] =1;
    int holdmin = 0;
    for(int i=2;i<=n;i++){
        if(ord[i-1][0]){
            ans[i] = ans[i-1]-pairs[i-1];
        }else{
            ans[i] = ans[i-1]+pairs[i-1];
        }
       
        holdmin = min(holdmin,ans[i]);
       
    }
    
    for(int i=1;i<=n;i++){
      if(holdmin<0){
         ans[i]+=abs(holdmin) + 1;
      }
       
        
    }
    
    bool ok = true;
    bool found = false;
    for(int i=1;i<n-1;i++){
        if(max(ans[i],max(ans[i+1],ans[i+2])) - min(ans[i],min(ans[i+1],ans[i+2]))!=triplets[i]){
            ok = false;
            break;
        }
        if(ans[i] == n){
            found = true;
        }
        if(ans[i] == 1  && found){
            ok = false;
            break;
        }
        
    }
  /*  for(int i=1;i<=n;i++){
        int maxi = arr[i];
        int mini = arr[i];
        for(int j=i+1;j<=n;j++){
            maxi = max(arr[j],maxi);
            mini = min(arr[j],mini);
            if(!check(i,j,mini,maxi)){
               // cout<<i<<" "<<j<<" "<<query(i,j)<<" "<<maxi-mini<<endl;
            }
        }
    }*/
    if(ok){
        for(int i=1;i<=n;i++){
            answer(i,ans[i]);
        }
        return;
    }
    ans[1] =1;
    holdmin = 0;
    for(int i=2;i<=n;i++){
        if(ord[i][1]){
            ans[i] = ans[i-1]+pairs[i-1];
        }else{
            ans[i] = ans[i-1]-pairs[i-1];
        }
        holdmin = min(holdmin,ans[i]);
       
     //   cout<<pairs[i-1]<<" "<<ans[i]<<endl;
    }
   // cout<<holdmin<<endl;
    
    
    for(int i=1;i<=n;i++){
         if(holdmin<0){
         ans[i]+=abs(holdmin) + 1;
      }
        
    }
    /* for(int i=1;i<=n;i++){
        int maxi = arr[i];
        int mini = arr[i];
        for(int j=i+1;j<=n;j++){
            maxi = max(arr[j],maxi);
            mini = min(arr[j],mini);
            if(!check(i,j,mini,maxi)){
               // cout<<i<<" "<<j<<" "<<query(i,j)<<" "<<maxi-mini<<endl;
            }
        }
    }*/
 
    for(int i=1;i<=n;i++){
        answer(i,ans[i]);
    }
    
}
/*int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    solve(n);
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 296 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 320 KB Output is correct
5 Incorrect 3 ms 248 KB Wrong Answer [7
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 296 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 320 KB Output is correct
5 Incorrect 3 ms 248 KB Wrong Answer [7
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 296 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 320 KB Output is correct
5 Incorrect 3 ms 248 KB Wrong Answer [7
6 Halted 0 ms 0 KB -