제출 #641871

#제출 시각아이디문제언어결과실행 시간메모리
641871ghostwriterPalembang Bridges (APIO15_bridge)C++14
8 / 100
17 ms2236 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 = 1e18;
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;
	}
}
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;
    }
    return 0;
}
/*
2 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 '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:64:5: note: in expansion of macro 'FOR'
   64 |     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...