답안 #698965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698965 2023-02-15T03:46:04 Z nguyentunglam Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 332 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 10;
pair<int, int> a[N];
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int k, n; cin >> k >> n;
    long long res = 0, total = 1e18;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        char p, q;
        int s, t; cin >> p >> s >> q >> t;
        if (p != q) {
            if (s > t) swap(s, t);
            a[++cnt] = make_pair(s, t);
            res++;
        }
        res += abs(s - t);
    }
    vector<int> lst;
    for(int i = 1; i <= n; i++) lst.push_back(a[i].fi), lst.push_back(a[i].se);
    for(int &j : lst) {
        if (j != 4) continue;
        long long ans = 0;
        for(int i = 1; i <= cnt; i++) {
            if (j < a[i].fi) ans += 2 * (a[i].fi - j);
            if (j > a[i].se) ans += 2 * (j - a[i].se);
        }
        total = min(total, res + ans);
    }
    cout << total << endl;
}


Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:13:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:14:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:17:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -