QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#854662#140. Palembang Bridges makrav0 0ms3828kbC++201.5kb2025-01-12 04:33:182025-01-12 04:33:18

Judging History

你现在查看的是最新测评结果

  • [2025-01-12 04:33:18]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3828kb
  • [2025-01-12 04:33:18]
  • 提交

answer

#include <bits/stdc++.h>
#include <cassert>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
#define int ll

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
void shuf(vector<T>& a) {
    for (int i = 1; i < sz(a); i++) swap(a[i], a[rnd() % (i + 1)]);
}

void solve() {
    int k, n; cin >> k >> n;
    vector<pair<int, int>> lol;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        char r1, r2;
        int p1, p2;
        cin >> r1 >> p1 >> r2 >> p2;
        if (r1 == r2) {
            ans += abs(p1 - p2);
            continue;
        }
        ans++;
        lol.pb({p1, p2});
    }

    vector<int> ap;
    for (int i = 0; i < sz(lol); i++) {
        ap.pb(lol[i].first); ap.pb(lol[i].second);
    }
    int best = 1e18;
    for (int p1 : ap){
        for (int p2 : ap) {
            int cur = 0;
            for (auto u : lol) {
                cur += min(abs(u.first - p1) + abs(u.second - p1), abs(u.first - p2) + abs(u.second - p2));
            }
            best = min(best, cur);
        }
    }
    cout << best + ans << '\n';
}

signed main() {
    int tt = 1;
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
    #endif

    while (tt--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3628kb

input:

1 1
B 426311872 B 741424667

output:

1000000000315112795

result:

wrong answer 1st lines differ - expected: '315112795', found: '1000000000315112795'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 0ms
memory: 3828kb

input:

2 1
B 822190955 B 309099167

output:

1000000000513091788

result:

wrong answer 1st lines differ - expected: '513091788', found: '1000000000513091788'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%