Submission #638775

#TimeUsernameProblemLanguageResultExecution timeMemory
638775ghostwriterXylophone (JOI18_xylophone)C++14
100 / 100
116 ms436 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.cpp" #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ #ifndef LOCAL static int A[5000]; #endif const int NMAX = 5e3 + 5; int a[NMAX], d[NMAX], d2[NMAX], d3[NMAX]; void solve(int N) { FOR(i, 2, N) d2[i] = query(i - 1, i); FOR(i, 3, N) d3[i] = query(i - 2, i); FOR(i, 3, N) { int a = d2[i - 1], b = d2[i]; if (a + b == d3[i]) d[i] = 0; else d[i] = 1; } bool op = 0; FOR(i, 2, N) { op ^= d[i]; a[i] = a[i - 1] + d2[i] * (op == 0? 1 : -1); } int pos1 = -1, posn = -1; FOR(i, 1, N) { if (pos1 == -1 || a[i] < a[pos1]) pos1 = i; if (posn == -1 || a[i] > a[posn]) posn = i; } // FOR(i, 1, N) { // debug(i, a[i]); // } // debug(pos1, posn); if (pos1 > posn) { FOR(i, 2, N) a[i] *= -1; swap(pos1, posn); } // FOR(i, 1, N) { // debug(i, a[i]); // } int diff = N - a[posn]; FOR(i, 1, N) a[i] += diff; FOR(i, 1, N) answer(i, a[i]); } /* 5 2 1 5 3 4 */

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:44:5: note: in expansion of macro 'FOR'
   44 |     FOR(i, 2, N) d2[i] = query(i - 1, i);
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i, 3, N) d3[i] = query(i - 2, i);
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:46:5: note: in expansion of macro 'FOR'
   46 |     FOR(i, 3, N) {
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:52:5: note: in expansion of macro 'FOR'
   52 |     FOR(i, 2, N) {
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:57:5: note: in expansion of macro 'FOR'
   57 |     FOR(i, 1, N) {
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:66:9: note: in expansion of macro 'FOR'
   66 |         FOR(i, 2, N) a[i] *= -1;
      |         ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:73:5: note: in expansion of macro 'FOR'
   73 |     FOR(i, 1, N) a[i] += diff;
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:74:5: note: in expansion of macro 'FOR'
   74 |     FOR(i, 1, N) answer(i, a[i]);
      |     ^~~
xylophone.cpp: At global scope:
xylophone.cpp:39:13: warning: 'A' defined but not used [-Wunused-variable]
   39 |  static int A[5000];
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...