제출 #647548

#제출 시각아이디문제언어결과실행 시간메모리
647548ghostwriter도서관 (JOI18_library)C++14
100 / 100
547 ms336 KiB
#include <cstdio> #include <vector> #include "library.h" using namespace std; #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.cpp" #else #define debug(...) #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #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 bg begin #define ed end #define all(x) (x).bg(), (x).ed() #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 FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(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); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- DIT ME CHUYEN BAO LOC ---------------------------------------------------------------- */ void Solve(int N) { if (N == 1) { Answer(vi(1, 1)); return; } vi ans(N, 0), M(N, 0); int bpos = -1; FRN(i, N) { EACH(j, M) j = 0; FRN(z, N) if (z != i) M[z] = 1; int cur = Query(M); if (cur == 1) bpos = i + 1; } ans[0] = bpos; vi index; FOR(i, 1, N) if (i != bpos) index.pb(i); FOR(i, 1, N - 1) { int l = 0, r = sz(index) - 1, ans1 = -1; WHILE(l <= r) { int mid = l + (r - l) / 2; EACH(j, M) j = 0; FRN(j, i) M[ans[j] - 1] = 1; FOR(j, 0, mid) M[index[j] - 1] = 1; int cur = Query(M); M[ans[i - 1] - 1] = 0; int cur1 = Query(M); if ((i > 1 && cur1 > cur) || (i == 1 && cur1 == cur)) { ans1 = mid; r = mid - 1; } else l = mid + 1; } ans[i] = index[ans1]; vi tmp; EACH(j, index) if (j != index[ans1]) tmp.pb(j); swap(index, tmp); } Answer(ans); } /* 5 4 2 5 3 1 ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */

컴파일 시 표준 에러 (stderr) 메시지

library.cpp: In function 'void Solve(int)':
library.cpp:39:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   39 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
library.cpp:64:2: note: in expansion of macro 'FRN'
   64 |  FRN(i, N) {
      |  ^~~
library.cpp:41:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   41 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
library.cpp:65:3: note: in expansion of macro 'EACH'
   65 |   EACH(j, M) j = 0;
      |   ^~~~
library.cpp:39:28: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   39 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
library.cpp:66:3: note: in expansion of macro 'FRN'
   66 |   FRN(z, N)
      |   ^~~
library.cpp:37:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   37 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
library.cpp:74:2: note: in expansion of macro 'FOR'
   74 |  FOR(i, 1, N)
      |  ^~~
library.cpp:37:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   37 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
library.cpp:77:2: note: in expansion of macro 'FOR'
   77 |  FOR(i, 1, N - 1) {
      |  ^~~
library.cpp:41:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   41 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
library.cpp:81:4: note: in expansion of macro 'EACH'
   81 |    EACH(j, M) j = 0;
      |    ^~~~
library.cpp:39:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   39 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
library.cpp:82:4: note: in expansion of macro 'FRN'
   82 |    FRN(j, i) M[ans[j] - 1] = 1;
      |    ^~~
library.cpp:37:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   37 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
library.cpp:83:4: note: in expansion of macro 'FOR'
   83 |    FOR(j, 0, mid) M[index[j] - 1] = 1;
      |    ^~~
library.cpp:41:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   41 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
library.cpp:95:3: note: in expansion of macro 'EACH'
   95 |   EACH(j, index)
      |   ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...