Submission #1107716

#TimeUsernameProblemLanguageResultExecution timeMemory
1107716KK_1729Xylophone (JOI18_xylophone)C++17
100 / 100
89 ms708 KiB
#include <bits/stdc++.h> using namespace std; #include "xylophone.h" // #define int long long #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define pb push_back #define all(a) a.begin(), a.end() #define endl "\n" void printVector(vector<int> a){ for (auto x: a) cout << x << " "; cout << endl; } void solve(int n){ vector<int> diff(n+1); FOR(i,1,n){ diff[i] = query(i, i+1); } vector<int> type(n+1, -1); type[1] = 1; FOR(i,1,n-1){ int e = query(i, i+2); if (e == diff[i]+diff[i+1]){ type[i+1] = type[i]; }else{ type[i+1] = type[i]^1; } } vector<int> a(n+1); FOR(i,1,n){ if (type[i] == 1){ a[i+1] = a[i]+diff[i]; }else{ a[i+1] = a[i]-diff[i]; } } int mini = 1e9; int maxi = 0; int minind = 0; int maxind = 0; FOR(i,1,n+1){ if (a[i] < mini){ minind = i; } if (a[i] > maxi){ maxind = i; } mini = min(mini, a[i]); maxi = max(maxi, a[i]); } // printVector(a); if (maxi - mini == n-1 && maxind > minind){ FOR(i,1,n+1){ answer(i, a[i]-(mini-1)); } return; } a.clear();a.resize(n+1); FOR(i,1,n){ if (type[i] == 1){ a[i+1] = a[i]-diff[i]; }else{ a[i+1] = a[i]+diff[i]; } } mini = 1e9; maxi = 0; FOR(i,1,n+1){ mini = min(mini, a[i]);maxi = max(maxi, a[i]); } FOR(i,1,n+1){ answer(i, a[i]-(mini-1)); } return; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...