제출 #641878

#제출 시각아이디문제언어결과실행 시간메모리
641878ghostwriterPalembang Bridges (APIO15_bridge)C++14
8 / 100
29 ms8208 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ const ll oo = 2e18; int k, n; vpi a; ll tv = 0, rs = oo; namespace subtask1 { void solve() { vi b; FOR(i, 1, n) { b.pb(a[i].st); b.pb(a[i].nd); } EACH(i, b) { ll sum = 0; FOR(j, 1, n) if (a[j].nd <= i) sum += 2 * i - a[j].st - a[j].nd + 1; else if (a[j].st >= i) sum += a[j].st + a[j].nd - 2 * i + 1; else sum += a[j].nd - a[j].st + 1; rs = min(rs, sum); } cout << tv + rs; } } namespace subtask2 { #define int long long const int N = 2e5 + 5; int prec[N], sufc[N]; ll pres[N], sufs[N]; bool cmp(pi &a, pi &b) { return a.nd < b.nd; } bool cmp1(pi &a, pi &b) { return a.st > b.st; } void solve() { FOR(i, 1, n) tv += a[i].nd - a[i].st + 1; vi b; FOR(i, 1, n) { b.pb(a[i].st); b.pb(a[i].nd); } sort(a.begin() + 1, a.end(), cmp); sort(all(b)); int l = 1, cnt = 0; ll sum = 0; FOR(i, 0, sz(b) - 1) { int x = b[i]; WHILE(l <= n && a[l].nd <= x) { ++cnt; sum += 2 * a[l].nd; ++l; } prec[i] = cnt; pres[i] = sum; } sort(a.begin() + 1, a.end(), cmp1); l = 1; cnt = 0; sum = 0; FOS(i, sz(b) - 1, 0) { int x = b[i]; WHILE(l <= n && a[l].st >= x) { if (a[l].st != a[l].nd) { ++cnt; sum += 2 * a[l].st; } ++l; } sufc[i] = cnt; sufs[i] = sum; } FOR(i, 0, sz(b) - 1) { int x = b[i]; rs = min(rs, 2LL * x * prec[i] - pres[i] + sufs[i] - 2LL * x * sufc[i]); } cout << tv + rs; } } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> k >> n; a.pb({0, 0}); FOR(i, 1, n) { char p, q; int s, t; cin >> p >> s >> q >> t; if (p == q) tv += abs(s - t); else a.pb({min(s, t), max(s, t)}); } n = sz(a) - 1; if (n == 0) { cout << tv; return 0; } if (k == 1 && n <= 1000) { subtask1::solve(); return 0; } if (k == 1 && n <= 1e5) { subtask2::solve(); return 0; } return 0; } /* 1 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */

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

bridge.cpp: In function 'void subtask1::solve()':
bridge.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bridge.cpp:43:3: note: in expansion of macro 'FOR'
   43 |   FOR(i, 1, n) {
      |   ^~~
bridge.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bridge.cpp:47:3: note: in expansion of macro 'EACH'
   47 |   EACH(i, b) {
      |   ^~~~
bridge.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bridge.cpp:49:4: note: in expansion of macro 'FOR'
   49 |    FOR(j, 1, n)
      |    ^~~
bridge.cpp: In function 'void subtask2::solve()':
bridge.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bridge.cpp:66:3: note: in expansion of macro 'FOR'
   66 |   FOR(i, 1, n) tv += a[i].nd - a[i].st + 1;
      |   ^~~
bridge.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bridge.cpp:68:3: note: in expansion of macro 'FOR'
   68 |   FOR(i, 1, n) {
      |   ^~~
bridge.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bridge.cpp:76:3: note: in expansion of macro 'FOR'
   76 |   FOR(i, 0, sz(b) - 1) {
      |   ^~~
bridge.cpp:25:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   25 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
bridge.cpp:90:3: note: in expansion of macro 'FOS'
   90 |   FOS(i, sz(b) - 1, 0) {
      |   ^~~
bridge.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bridge.cpp:102:3: note: in expansion of macro 'FOR'
  102 |   FOR(i, 0, sz(b) - 1) {
      |   ^~~
bridge.cpp: In function 'int main()':
bridge.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bridge.cpp:115:5: note: in expansion of macro 'FOR'
  115 |     FOR(i, 1, n) {
      |     ^~~
#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...