Submission #561330

#TimeUsernameProblemLanguageResultExecution timeMemory
561330Joshi503Teams (IOI15_teams)C++14
34 / 100
4086 ms10336 KiB
#include <teams.h> #include <bits/stdc++.h> using namespace std; using ll = long long; using db = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; #define f first #define s second #define tcT template<class T #define tcTU tcT, class U tcT> using V = vector<T>; tcT, size_t SZ > using AR = array<T, SZ>; using vi = V<int>; using vb = V<bool>; using vl = V<ll>; using vd = V<db>; using vs = V<str>; using vpi = V<pi>; using vpl = V<pl>; #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define pb push_back #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 rep(a) F0R(_,a) #define each(a,x) for (auto& a: x) const ll MOD = 1e9 + 7; const ll MX = 1e9; const ll INF = 1e18; const db PI = acos((db)-1); const int ddef[4]{ 1,0,-1,0 }, dataq[4]{ 0,1,0,-1 }; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>; void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if (sz(name)) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } void _print(char i) { cerr << i; } void _print(string i) { cerr << i; } void _print(float i) { cerr << i; } void _print(int i) { cerr << i; } void _print(double i) { cerr << i; } void _print() { cerr << "\n"; }; template<typename x, typename y> void _print(pair<x, y>& t) { cerr << "{";_print(t.first);cerr << ", ";_print(t.second);cerr << "},"; } template<typename x> void _print(x& t) { cerr << "{"; for (int i = 0;i < (int)t.size();i++) { _print(t[i]); if (i < (int)t.size() - 1) cerr << ", "; } cerr << "}"; } template<typename x, typename... y> void _print(x a, y... b) { _print(a);if (sizeof...(b)) cerr << ", ";_print(b...); } #define dbg(x...) cerr<<"["<<#x<<"] = [";_print(x);cerr<<"]\n"; int n; const int MXN = 500001; vector<pi> alfa(MXN); bool cmp(const pi& x, const pi& y){ if(x.f == y.f){ return x.s < y.s; } return x.s < y.s; } void init(int N, int A[], int B[]) { n = N; F0R(i, n){ alfa[i].f = A[i]; } F0R(i, n){ alfa[i].s = B[i]; } sort(alfa.begin(), alfa.begin() + n, cmp); // F0R(i, n){ // cout << alfa[i].f << " "; // } // cout << "\n"; // F0R(i, n){ // cout << alfa[i].s << " "; // } // cout << "\n"; } int can(int M, int K[]) { vector<pair<int, int>> a(M); vi k(M); vi idk(M); F0R(i, M){ a[i].f = K[i]; a[i].s = i; } sor(a); F0R(i, M){ k[i] = a[i].f; idk[i] = a[i].s; } vi taken(M, 0); F0R(i, n){ auto it = lower_bound(all(k), alfa[i].f); int idx = (int)(it - k.begin()); // cout << idx << " " << sz(k) << "\n"; // F0R(j, sz(k)){ // cout << k[j] << " "; // } // cout << "a\n"; if(sz(k) && idx >= 0 && idx < M && k[idx] >= alfa[i].f && k[idx] <= alfa[i].s){ taken[idk[idx]]++; // cout << idk[idx] << " " << taken[idk[idx]] << "\n"; if(taken[idk[idx]] == K[idk[idx]]){ k.erase(k.begin() + idx); idk.erase(idk.begin() + idx); } } else{ idx--; if(sz(k) && idx >= 0 && idx < M && k[idx] >= alfa[i].f && k[idx] <= alfa[i].s){ taken[idk[idx]]++; // cout << alfa[i].f << "b " << alfa[i].s << " " << k[idx] << " " << taken[idk[idx]] << "\n"; if(taken[idk[idx]] == K[idk[idx]]){ k.erase(k.begin() + idx); idk.erase(idk.begin() + idx); } } } } return sz(k) == 0; }

Compilation message (stderr)

teams.cpp: In function 'void setIO(std::string)':
teams.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen((name + ".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...