제출 #707808

#제출 시각아이디문제언어결과실행 시간메모리
707808marvinthang팀들 (IOI15_teams)C++17
77 / 100
4059 ms388012 KiB
/************************************* * author: marvinthang * * created: 06.03.2023 21:08:07 * *************************************/ #include "teams.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define REPD(i, n) for (int i = (n); i--; ) #define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; ) #define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #ifdef LOCAL #include "debug.h" #else #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define DB(...) 23 #define db(...) 23 #define debug(...) 23 #endif template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; } template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; } template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); } template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; } struct Node { Node *lc, *rc; int sum; Node(int v = 0): lc(nullptr), rc(nullptr), sum(v) {} Node(Node *l, Node *r): lc(l), rc(r), sum(0) { if (l != nullptr) sum += l->sum; if (r != nullptr) sum += r->sum; } }; Node *build(int l, int r) { if (l == r) return new Node(); int m = l + r >> 1; return new Node(build(l, m), build(m + 1, r)); } Node *update(Node *cur, int l, int r, int p, int v) { if (l == r) return new Node(cur->sum + v); int m = l + r >> 1; if (p <= m) return new Node(update(cur->lc, l, m, p, v), cur->rc); return new Node(cur->lc, update(cur->rc, m + 1, r, p, v)); } int get_sum(Node *cur, int l, int r, int u, int v) { if (l > v || r < u) return 0; if (u <= l && r <= v) return cur->sum; int m = l + r >> 1; return get_sum(cur->lc, l, m, u, v) + get_sum(cur->rc, m + 1, r, u, v); } // end of template const int MAX = 5e5 + 5; const int BLOCK_SIZE = 707; int N, pref[MAX]; Node *versions[MAX]; vector <int> leftAt[MAX]; void init(int n, int A[], int B[]) { N = n; REP(i, N) { leftAt[A[i]].push_back(B[i]); ++pref[A[i]]; --pref[B[i] + 1]; } versions[0] = build(1, N); FOR(i, 1, N) { pref[i] += pref[i - 1]; versions[i] = versions[i - 1]; for (int r: leftAt[i]) versions[i] = update(versions[i], 1, N, r, 1); } } int cnt[MAX], dp[MAX]; int can(int M, int K[]) { long long sum = 0; REP(i, M) sum += K[i]; if (sum > N) return 0; REP(i, M) ++cnt[K[i]]; vector <pair <int, int>> v; REP(i, M) if (cnt[K[i]]) { v.push_back(make_pair(K[i], K[i] * cnt[K[i]])); cnt[K[i]] = 0; } sort(ALL(v)); M = v.size(); REP(i, M) { dp[i] = 0; REP(j, i) minimize(dp[i], dp[j] - get_sum(versions[v[j].fi], 1, N, v[i].fi, N)); dp[i] += pref[v[i].fi] - v[i].se; if (dp[i] < 0) return 0; } return 1; } #ifdef LOCAL #include <stdio.h> #include <stdlib.h> static char _buffer[1024]; static int _currentChar = 0; static int _charsNumber = 0; static FILE *_inputFile, *_outputFile; static inline int _read() { if (_charsNumber < 0) { exit(1); } if (!_charsNumber || _currentChar == _charsNumber) { _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile); _currentChar = 0; } if (_charsNumber <= 0) { return -1; } return _buffer[_currentChar++]; } static inline int _readInt() { int c, x, s; c = _read(); while (c <= 32) c = _read(); x = 0; s = 1; if (c == '-') { s = -1; c = _read(); } while (c > 32) { x *= 10; x += c - '0'; c = _read(); } if (s < 0) x = -x; return x; } int main() { _inputFile = fopen("teams.in", "rb"); _outputFile = fopen("teams.out", "w"); int N; N = _readInt(); int *A = (int*)malloc(sizeof(int)*(unsigned int)N); int *B = (int*)malloc(sizeof(int)*(unsigned int)N); for (int i = 0; i < N; ++i) { A[i] = _readInt(); B[i] = _readInt(); } init(N, A, B); int Q; Q = _readInt(); for (int i = 0; i < Q; ++i) { int M; M = _readInt(); int *K = (int*)malloc(sizeof(int)*(unsigned int)M); for (int j = 0; j < M; ++j) { K[j] = _readInt(); } fprintf(_outputFile,"%d\n", can(M, K)); } return 0; } #endif

컴파일 시 표준 에러 (stderr) 메시지

teams.cpp: In function 'Node* build(int, int)':
teams.cpp:58:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |  int m = l + r >> 1;
      |          ~~^~~
teams.cpp: In function 'Node* update(Node*, int, int, int, int)':
teams.cpp:64:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |  int m = l + r >> 1;
      |          ~~^~~
teams.cpp: In function 'int get_sum(Node*, int, int, int, int)':
teams.cpp:72:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |  int m = l + r >> 1;
      |          ~~^~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:114:12: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  114 |  M = v.size();
      |      ~~~~~~^~
teams.cpp:20:46: warning: declaration of '_n' shadows a previous local [-Wshadow]
   20 | #define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
      |                                              ^~
teams.cpp:117:3: note: in expansion of macro 'REP'
  117 |   REP(j, i) minimize(dp[i], dp[j] - get_sum(versions[v[j].fi], 1, N, v[i].fi, N));
      |   ^~~
teams.cpp:20:46: note: shadowed declaration is here
   20 | #define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
      |                                              ^~
teams.cpp:115:2: note: in expansion of macro 'REP'
  115 |  REP(i, 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...