Submission #480293

#TimeUsernameProblemLanguageResultExecution timeMemory
480293arwaeystoamnegXylophone (JOI18_xylophone)C++17
100 / 100
136 ms356 KiB
// EXPLOSION! #define _CRT_SECURE_NO_WARNINGS #ifndef arwaeystoamneg #include"bits/stdc++.h" #endif #ifdef arwaeystoamneg #include<iostream> #include<algorithm> #include<vector> #include<unordered_set> #include<unordered_map> #include<chrono> #include<cassert> #endif using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpi; typedef vector<pair<ll, ll>> vpll; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define mp make_pair #define rsz resize #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define f first #define s second #define cont continue #define endl '\n' //#define ednl '\n' #define test int testc;cin>>testc;while(testc--) #define pr(a, b) trav(x,a)cerr << x << b; cerr << endl; #define message cout << "Hello World" << endl; const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!! const ll linf = 4000000000000000000LL; const ll inf = 998244353;// 1000000007 void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; } }void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; } void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef arwaeystoamneg if (sz(s)) { freopen((s + ".in").c_str(), "r", stdin); if (s != "test1") freopen((s + ".out").c_str(), "w", stdout); } #endif } #ifndef arwaeystoamneg #include "xylophone.h" #endif #ifdef arwaeystoamneg static int A[5000]; static const int N_MAX = 5000; static const int Q_MAX = 10000; static int N; static bool used[N_MAX]; static int query_c; static int answer_c; int query(int u, int t) { if (query_c >= Q_MAX) { printf("Wrong Answer\n"); exit(0); } query_c++; if (!(1 <= u && u <= t && t <= N)) { printf("Wrong Answer\n"); exit(0); } int mx = 0, mn = N + 1; for (int i = u - 1; i < t; i++) { if (mx < A[i]) { mx = A[i]; } if (mn > A[i]) { mn = A[i]; } } return mx - mn; } void answer(int i, int a) { answer_c++; if (!(1 <= i && i <= N)) { printf("Wrong Answer\n"); exit(0); } if (!(1 <= a && a <= N)) { printf("Wrong Answer\n"); exit(0); } if (used[i - 1]) { printf("Wrong Answer\n"); exit(0); } if (a != A[i - 1]) { printf("Wrong Answer\n"); exit(0); } used[i - 1] = true; } #endif int n; vi a; void solve(int N) { n = N; a.rsz(n); a[0] = 0; a[1] = query(1, 2); FOR(i, 2, n) { int d = query(i, i + 1); int d1 = query(i - 1, i + 1); if (a[i - 2] < a[i - 1]) { if (abs(a[i - 2] - (a[i - 1] + d)) == d1)a[i] = a[i - 1] + d; else a[i] = a[i - 1] - d; } else { if (abs(a[i - 2] - (a[i - 1] - d)) == d1)a[i] = a[i - 1] - d; else a[i] = a[i - 1] + d; } } int m = *min_element(all(a)); m = abs(m); trav(x, a)x += m; if (min_element(all(a)) > max_element(all(a)))trav(x, a)x = n - x - 1; F0R(i, n)answer(i + 1, a[i] + 1); } #ifdef arwaeystoamneg int main() { query_c = 0; answer_c = 0; if (scanf("%d", &N) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } for (int i = 0; i < N; i++) { if (scanf("%d", A + i) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } used[i] = false; } solve(N); if (!(answer_c == N)) { printf("Wrong Answer\n"); exit(0); } printf("Accepted : %d\n", query_c); } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...