Submission #897902

#TimeUsernameProblemLanguageResultExecution timeMemory
897902whatthemomooofun1729Carnival (CEOI14_carnival)C++14
100 / 100
4 ms708 KiB
#include <iostream> #include <algorithm> #include <utility> #include <vector> #include <stack> #include <map> #include <queue> #include <set> #include <unordered_set> #include <unordered_map> #include <cstring> #include <cmath> #include <functional> #include <cassert> #include <iomanip> #include <numeric> #include <bitset> #include <sstream> #include <chrono> #include <random> #define ff first #define ss second #define ll long long #define ld long double #define PB push_back #define MP make_pair #define MT make_tuple #define EB emplace_back #define PoB pop_back #define LOG log2 #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 fch(t, v) for (auto t : v) #define sz(x) int(x.size()) #define rsz resize #define gp(x) vector<vector<x>> #define btree vector<pii> #define vc(x) vector<x> #define vll vector<ll> #define Max(a, b, c) max(max(a,b),c) #define fMax(a, b, c, d) max(Max(a, b, c), dp) #define Min(a, b, c) min(min(a,b),c) #define Mid(a, b, c) max(min(a, b), min(max(a, b), c)) #define st(a) set<a> #define gr(x) greater<x> #define gi greater<int> #define all(x) (x).begin(),(x).end() #define tri(x) tuple<x,x,x> #define pil pair<int, long> #define ull unsigned long long #define eps 1e-9 //#define debug(x) cout << '>' << #x << ':' << x << endl; using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} void println() {cerr << ">--------------------<" << endl;} void printm(vector<vector<int>>& mat) { cerr << "matrix: " << endl; for (int i = 0; i<(int)mat.size(); i++) {for (int j = 0; j<(int)mat[0].size(); j++) {cerr << mat[i][j] << " ";} cerr << endl;} } #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; // templates template <class T> bool ckmin(T &a, const T &b) {return b<a ? a = b, 1 : 0;} template <class T> bool ckmax(T &a, const T &b) {return b>a ? a = b, 1 : 0;} mt19937_64 rng_ll(chrono::steady_clock::now().time_since_epoch().count()); int rng(int M) {return (int)(rng_ll()%M);} constexpr int INF = (int)2e9; constexpr int MOD = 998244353; constexpr ll LL_INF = (ll)3e18; constexpr int mod = (int)1e9 + 7; constexpr ll inverse = 500000004LL; // inverse of 2 modulo 1e9 + 7 void setIO(const string& str) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (str.empty()) return; freopen((str + ".in").c_str(), "r", stdin); freopen((str + ".out").c_str(), "w", stdout); } int N; vi parent, val; int find_set(int v) { if (parent[v] == v) return v; return parent[v] = find_set(parent[v]); } void no_one_asked(vector<int>& v, int i) { // ask nontrivial cout << sz(v) + 1 << ' '; fch(x, v) cout << x << ' '; cout << i << endl; } int main() { // TIME YOURSELF !!! setIO(""); cin >> N; vi v; parent.rsz(N+1), val.rsz(N+1, 0); iota(parent.begin() + 1, parent.end(), 1); for (int i = 1; i <= N; ++i) { no_one_asked(v, i); int M; cin >> M; if (M == sz(v) + 1) v.PB(i); else { int l = 0, r = sz(v) - 1, pos = INF; while (l <= r) { int mid = (l + r)/2; cout << mid+2 << ' ' << i << ' '; for (int j = 0; j <= mid; ++j) { cout << v[j] << ' '; } cout << endl; cin >> M; if (M == mid + 1) { r = mid - 1; ckmin(pos, mid); } else l = mid + 1; } parent[i] = v[pos]; } } int cnt = 1; cout << "0 "; for (int i = 1; i <= N; ++i) { int p = find_set(i); if (!val[p]) val[p] = cnt++; cout << val[p] << ' '; } return 0; } // CHECK LONG LONGS, binary search on ans? // Do something, start simpler // IBM motto: THINK

Compilation message (stderr)

carnival.cpp: In function 'void setIO(const string&)':
carnival.cpp:112:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     freopen((str + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
carnival.cpp:113:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |     freopen((str + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...