Submission #759572

#TimeUsernameProblemLanguageResultExecution timeMemory
759572otariusXylophone (JOI18_xylophone)C++17
0 / 100
0 ms208 KiB
#include "xylophone.h" #include <iostream> #include <algorithm> #include <vector> #include <set> #include <cstring> #include <queue> #include <map> #include <cmath> #include <iomanip> using namespace std; #define ff first #define sc second #define pb push_back #define ll long long #define pll pair<ll, ll> #define pii pair <int, int> #define ull unsigned long long // #define int long long // #define int unsigned long long const ll inf = 1e9 + 7; const ll weirdMod = 998244353; bool check(vector<int> v, int n) { set<int> st; for (int u : v) st.insert(u); if (st.size() != n) return false; int cur = 1; for (int u : st) { if (cur == u) cur++; else return false; } return true; } void solve(int n) { int b[n + 1], c[n + 1]; for (int i = 1; i <= n - 1; i++) b[i] = query(i, i + 1); for (int i = 1; i <= n - 2; i++) c[i] = query(i, i + 2); bool flg[n + 1]; /* flg[i] = 1, if a[i] > a[i + 1] flg[i] = 0, if a[i] < a[i + 1] */ flg[1] = 1; for (int i = 2; i < n; i++) { if (b[i - 1] + b[i] == c[i - 1]) { flg[i] = flg[i - 1]; flg[i + 1] = flg[i]; } else { flg[i] = flg[i - 1]; flg[i + 1] = !flg[i]; } } int mn = 1, cur = 1; vector<int> a; for (int i = 2; i <= n; i++) { if (flg[i - 1]) { cur -= b[i - 1]; mn = min(mn, cur); a.pb(cur); } else { cur += b[i - 1]; mn = min(mn, cur); a.pb(cur); } } for (int &v : a) v += -mn + 1; if (check(a, n)) { for (int i = 0; i < a.size(); i++) answer(i + 1, a[i]); return; } mn = 1; cur = 1; a.clear(); for (int i = 2; i <= n; i++) { if (flg[i - 1]) { cur += b[i - 1]; mn = min(mn, cur); a.pb(cur); } else { cur -= b[i - 1]; mn = min(mn, cur); a.pb(cur); } } for (int &v : a) v += -mn + 1; for (int i = 0; i < a.size(); i++) answer(i + 1, a[i]); }

Compilation message (stderr)

xylophone.cpp: In function 'bool check(std::vector<int>, int)':
xylophone.cpp:31:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     if (st.size() != n)
      |         ~~~~~~~~~~^~~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:69:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for (int i = 0; i < a.size(); i++)
      |                         ~~^~~~~~~~~~
xylophone.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (int i = 0; i < a.size(); i++)
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...