QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#870233#8591. Shopsdreamboy#0 12ms3712kbC++203.1kb2025-01-25 15:26:592025-01-25 15:27:07

Judging History

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

  • [2025-01-25 15:27:07]
  • 评测
  • 测评结果:0
  • 用时:12ms
  • 内存:3712kb
  • [2025-01-25 15:26:59]
  • 提交

answer

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;

// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("O3")

#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define russian setlocale(LC_ALL,"Russian_Russia.20866");
#define file freopen("onlyone.in", "r", stdin), freopen("onlyone.out", "w", stdout);
#define ll long long
#define big __int128
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pii pair<int, int>
#define all(s) s.begin(), s.end()
#define pb push_back
#define ins insert
#define sz(x) x.size()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mem(x) memset(x, 0, sizeof(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 500010;
const int B = 448;
const ll mod = 998244353;
const ll P = 263;
const ld pi = acos(-1);
const ll inf = (ll)1e18;
const ll ntr = (ll)-1e18;

ll add(ll a, ll b) {
    if(a + b < 0) return a + b + mod;
    if(a + b >= mod) return a + b - mod;
    return a + b;
}

ll sub(ll a, ll b) {
    return (a - b + mod) % mod;
}

ll mul(ll a, ll b) {
    return a * 1LL * b % mod;
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while(n) {
        if (n & 1) res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}

ll inv(ll x) {
    return binpow(x, mod - 2);
}
int n, m;
ll dst[20][20];
void sub1() {
    pair<ll, string> ans = {LLONG_MAX, ""}, cur = {0LL, ""};
    vector<int> b, d;
    for(int msk = 1; msk < (1 << n) - 1; msk++) {
        b.clear(); d.clear();
        cur = {0LL, ""};
        for(int i = 0; i < n; i++) {
            if((msk & (1 << i))) {
                cur.S += 'B';
                b.pb(i + 1);
            }
            else {
                cur.S += 'D';
                d.pb(i + 1);
            }
        }
        for(auto i: b) {
            for(auto j: d) {
                cur.F = max(cur.F, dst[i][j]);
            }
        }
        for(auto i: d) {
            for(auto j: b) {
                cur.F = max(cur.F, dst[i][j]);
            }
        }
        if(ans.F > cur.F) ans = cur;
    }
    cout << ans.F << '\n' << ans.S << '\n';
}
void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            dst[i][j] = 1e17;
        }
    }
    for(int i = 1; i <= n; i++) {
        dst[i][i] = 0LL;
    }
    for(int i = 1, v1, v2, w; i <= m; i++) {
        cin >> v1 >> v2 >> w;
        dst[v1][v2] = min(dst[v1][v2], 1LL * w);
        dst[v2][v1] = min(dst[v2][v1], 1LL * w);
    }
    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                dst[i][j] = min(dst[i][j], dst[i][k] + dst[k][j]);
            }
        }
    }
    if(n <= 16) {
        sub1();
        return;
    }
}
signed main() {
    speed;
    //file
    int test = 1;
    //cin >> test;
    while(test--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 0ms
memory: 3584kb

input:

3 3
1 2 3
2 3 1
1 3 2

output:

2
BBD

result:

ok inconveniences = 2

Test #2:

score: 7
Accepted
time: 0ms
memory: 3584kb

input:

5 6
3 2 3
4 2 1
5 3 9
1 3 5
1 4 2
2 3 1

output:

9
DDBDD

result:

ok inconveniences = 9

Test #3:

score: 0
Wrong Answer
time: 12ms
memory: 3712kb

input:

8 135737
1 4 763713071
3 7 45141437
4 8 618418466
6 8 91803956
7 5 972595945
5 2 751163228
2 8 9886315
4 3 106470622
8 6 949495949
1 2 885918825
4 6 322040168
7 6 754489330
4 8 618968328
5 3 996860159
3 6 210132897
3 4 591744987
8 7 447985622
2 4 4833956
5 7 610154418
2 5 410116873
2 5 912717336
8 7...

output:

61947
DDBDDDDD

result:

wrong answer your plan is not optimal: read 61947 but expected 19258

Subtask #2:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

input:

500000 499999
1 2 776715136
2 3 406881694
3 4 265792290
4 5 507607272
5 6 182246639
6 7 997847597
7 8 164130256
8 9 278962226
9 10 411194641
10 11 363646402
11 12 672225656
12 13 494629089
13 14 717664153
14 15 121619271
15 16 476857704
16 17 301215244
17 18 810217743
18 19 850722975
19 20 10710274
...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Runtime Error

Test #31:

score: 0
Runtime Error

input:

366489 397001
2 127909 1
7 171229 1
8 158597 1
11 282213 1
14 356007 1
15 286102 1
16 93205 1
17 260111 1
18 138962 1
20 359938 1
29 223905 1
31 357684 1
32 259968 1
34 65205 1
37 200276 1
41 83195 1
43 159858 1
48 332277 1
50 320322 1
51 338467 1
53 262785 1
55 83815 1
56 173198 1
58 169473 1
63 19...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%