제출 #321507

#제출 시각아이디문제언어결과실행 시간메모리
321507CaroLindaXylophone (JOI18_xylophone)C++14
0 / 100
1 ms364 KiB
#include "xylophone.h" #include <bits/stdc++.h> #define sz(x) (int)(x.size() ) #define all(x) x.begin(),x.end() const int MAX = 5010 ; using namespace std ; map< pair<int,int> , int > mp ; void trying(vector<int> &vec ) { for(int i = 3 ; i < sz(vec) ; i++ ) { int val12 = abs(vec[i-1]-vec[i-2] ) ; int val23 = mp[ make_pair(i-1,i) ] ; int val13 = mp[ make_pair(i-2,i) ] ; if(val12 + val23 == val13 ) { vec[i] = vec[i-2] + val13 ; if( vec[i-1] < vec[i-2] ) vec[i] = vec[i-2] - val13 ; } else { vec[i] = vec[i-1] + val23 ; if( vec[i-1] > vec[i-2] ) vec[i] = vec[i-1] - val23 ; } } int mn = *min_element(all(vec) ) ; for(int &i : vec ) i += 1-mn ; } void giveAns(vector<int> vec) { for(int i = 1 ; i < sz(vec) ; i++ ) answer(i,vec[i] ) ; exit(0) ; } void solve(int n) { int firstAbs = query(1,2) ; vector<int> seq1(n+1,0) ; //a[1] < a[2] vector<int> seq2(n+1, 0) ; //a[1] > a[2] seq1[2] = firstAbs ; seq2[2] = -firstAbs ; for(int i = 3 ; i <= n ; i++ ) { mp[ make_pair(i-2,i) ] = query(i-2, i) ; mp[ make_pair(i-1,i) ] = query(i-1,i) ; } trying(seq1) ; trying(seq2) ; int idx1 = -1, idx2 = -1 ; for(int i = 1 ; i <= n ; i++ ) if(seq1[i] == 1 ) idx1 = i ; for(int i = 1 ; i <= n ; i++ ) if(seq2[i] == 1 ) idx2 =i ; if(idx1 == -1 ) giveAns(seq2) ; if(idx2 == -1 ) giveAns(seq1) ; if(idx2 > idx1 ) { if(query(idx2, n) == n-1 ) giveAns(seq2) ; giveAns(seq1) ; } else { if(query(idx1, n) == n-1 ) giveAns(seq1); giveAns(seq2) ; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...