제출 #951280

#제출 시각아이디문제언어결과실행 시간메모리
951280quanlt206Xylophone (JOI18_xylophone)C++17
100 / 100
149 ms1256 KiB
#include "xylophone.h" #include<bits/stdc++.h> #define X first #define Y second #define all(x) begin(x), end(x) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FORD(i, b, a) for(int i = (b); i >= (a); i--) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define mxx max_element #define mnn min_element #define SQR(x) (1LL * (x) * (x)) #define MASK(i) (1LL << (i)) #define Point Vector #define left Left #define right Right #define div Div using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<db, db> pdb; typedef pair<ld, ld> pld; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; typedef pair<ll, int> pli; typedef pair<ll, pii> plii; template<class A, class B> bool maximize(A& x, B y) { if (x < y) return x = y, true; else return false; } template<class A, class B> bool minimize(A& x, B y) { if (x > y) return x = y, true; else return false; } /* END OF TEMPLATE */ const int N = 5007; int n, b[N], a[N]; int cntQuery = 0; int relation[N], diff[N]; int c[N], cnt[N]; vector<int> get_permutation() { vector<int> tmp; FOR(t, 1, n) { c[1] = t; FOR(i, 2, n) if (relation[i - 1] == 0) c[i] = c[i - 1] + diff[i - 1]; else c[i] = c[i - 1] - diff[i - 1]; FOR(i, 1, n) cnt[i] = 0; bool kt = true; FOR(i, 1, n) if (c[i] < 1 || c[i] > n || (++cnt[c[i]]) > 1) kt = false; if (kt) return vector<int>(c + 1, c + 1 + n); } return tmp; } bool check(vector<int> node) { if (node.empty()) return false; int pos_1 = 0, pos_n = 0; REP(i, 0, n) if (node[i] == 1) pos_1 = i + 1; else if (node[i] == n) pos_n = i + 1; if (pos_1 > pos_n) return false; return query(pos_1, pos_n) == n - 1 && query(pos_1, pos_n - 1) != n - 1; } void solve(int m) { n = m; FOR(i, 1, n) a[i] = 0, relation[i] = 0; REP(i, 1, n) diff[i] = query(i, i + 1); REP(i, 1, n - 1) if (query(i, i + 2) != diff[i] + diff[i + 1]) relation[i + 1] = relation[i] ^ 1; else relation[i + 1] = relation[i]; vector<int> node = get_permutation(); // REP(i, 1, n) cout<<relation[i]<<" "; cout<<"\n"; // for (auto x : node) cout<<x<<" "; cout<<"\n"; // exit(0); if (check(node)) { REP(i, 0, n) a[i + 1] = node[i]; } else { REP(i, 1, n) relation[i]^=1; node = get_permutation(); REP(i, 0, n) a[i + 1] = node[i]; } FOR(i, 1, n) answer(i, a[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...