Submission #1100971

#TimeUsernameProblemLanguageResultExecution timeMemory
1100971RiverFlowTeams (IOI15_teams)C++14
21 / 100
4067 ms32332 KiB
#include <bits/stdc++.h> #define nl "\n" #define no "NO" #define yes "YES" #define fi first #define se second #define vec vector #define task "main" #define _mp make_pair #define ii pair<int, int> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define evoid(val) return void(std::cout << val) #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FOD(i, b, a) for(int i = (b); i >= (a); --i) #define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin()) using namespace std; template<typename U, typename V> bool maxi(U &a, V b) { if (a < b) { a = b; return 1; } return 0; } template<typename U, typename V> bool mini(U &a, V b) { if (a > b) { a = b; return 1; } return 0; } const int N = (int)2e5 + 9; const int mod = (int)1e9 + 7; void prepare(); void main_code(); int n, m; int a[N], b[N], c[N], k[N]; vector<int> ins[N]; void init(int N, int A[], int B[]) { n = N; FOR(i, 0, n - 1) { a[i] = A[i], b[i] = B[i]; } } int dp[N]; int can(int M, int K[]) { int m = M; long long sum = 0; for(int i = 0; i < m; ++i) k[i] = K[i], sum += k[i]; if (sum > n) return 0; sort(k, k + m); int nm = 0; for(int i = 0; i < m; ++i) { int j = i; while (j + 1 < m and k[j + 1] == k[i]) ++j; c[nm] = j - i + 1; k[nm++] = k[i]; i = j; } m = nm; for(int i = 0; i < m; ++i) { // f(i) tap cac dinh duoc tao moi, g(i) tap cac hoc sinh // dp(i): min chenh lech |g(i)| - |f(i)| // xet k[i] -> ta cnt so luong int cnt = 0; FOR(j, 0, n - 1) cnt += a[j] <= k[i] and k[i] <= b[j]; if (cnt < k[i] * c[i]) { return 0; } dp[i] = cnt - k[i] * c[i]; for(int j = 0; j < i; ++j) { // end at j int cx = 0; FOR(t, 0, n - 1) if (a[t] > k[j] and a[t] <= k[i] and b[t] >= k[i]) { ++cx; } mini(dp[i], cx - k[i] * c[i] + dp[j]); } if (dp[i] < 0) return 0; } return 1; } #ifdef LOCAL int aa[N], bb[N], kk[N]; int main() { freopen("main.inp", "r", stdin); freopen("main.ans", "w", stdout); int n; cin >> n; FOR(i, 0, n - 1) cin >> aa[i] >> bb[i]; init(n, aa, bb); int q; cin >> q; while (q--) { int m; cin >> m; FOR(i, 0, m - 1) cin >> kk[i]; cout << can(m, kk) << nl; } } #endif

Compilation message (stderr)

teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:39:15: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   39 | void init(int N, int A[], int B[]) {
      |           ~~~~^
teams.cpp:28:11: note: shadowed declaration is here
   28 | const int N = (int)2e5 + 9;
      |           ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:49:9: warning: declaration of 'm' shadows a global declaration [-Wshadow]
   49 |     int m = M;
      |         ^
teams.cpp:33:8: note: shadowed declaration is here
   33 | int n, m;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...