답안 #503654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503654 2022-01-08T14:23:16 Z XII 시간이 돈 (balkan11_timeismoney) C++17
40 / 100
103 ms 460 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "timeismoney_TernarySearch"
void Fi(){
    if(fopen(PROB".inp", "r")){
        freopen(PROB".inp", "r", stdin);
        freopen(PROB".out", "w", stdout);
    }
}

const int N = 200 + 1;
const int M = 10000 + 1;
const double MAX = 1e5;

struct edge{
    int u, v, t, c;
    ll w;
    const bool operator<(const edge &ot){
        return w < ot.w;
    }
};
vector<edge> ed;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
int n, m;
pl ans;
pi mst[N];
int cnt;

int par[N];
void init(){
    FOR(i, 0, n) par[i] = -1;
}
int root(int v){
    return (par[v] < 0) ? v : par[v] = root(par[v]);
}
bool join(int x, int y){
    if((x = root(x)) == (y = root(y))) return false;
    if(-par[x] < -par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
}

ll check(const double &X){
    for(edge &x: ed){
        x.w = (x.t * X + x.c * (MAX - X));
    }
    sort(ALL(ed));
    cnt = 0;
    ans = {0, 0};
    init();
    for(edge x: ed){
        if(join(x.u, x.v)){
            ans.fi += x.t;
            ans.se += x.c;
            mst[++cnt] = {x.u, x.v};
        }
    }
    return ans.fi * ans.se;
}

int main(){
    IOS;
    Fi();
    cin >> n >> m;
    ed.resize(m);
    for(edge &x: ed) cin >> x.u >> x.v >> x.t >> x.c;
    double l = 0, h = MAX;
    for(int step = 1; step <= 200; ++step){
        double m1 = l + (h - l) / 3;
        double m2 = h - (h - l) / 3;
        if(check(m1) > check(m2)) h = m2;
        else l = m1;
    }
    check(l);
    cout << ans.fi << " " << ans.se << "\n";
    FOR(i, 1, n) cout << mst[i].fi << " " << mst[i].se << "\n";
    return 0;
}

Compilation message

timeismoney.cpp: In function 'void Fi()':
timeismoney.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
timeismoney.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 4 ms 204 KB Output is correct
6 Correct 3 ms 204 KB Output is correct
7 Correct 18 ms 368 KB Output is correct
8 Correct 78 ms 460 KB Output is correct
9 Incorrect 1 ms 204 KB Output isn't correct
10 Incorrect 1 ms 204 KB Output isn't correct
11 Incorrect 1 ms 204 KB Output isn't correct
12 Incorrect 1 ms 204 KB Output isn't correct
13 Incorrect 1 ms 320 KB Output isn't correct
14 Incorrect 4 ms 332 KB Output isn't correct
15 Incorrect 3 ms 320 KB Output isn't correct
16 Incorrect 16 ms 360 KB Output isn't correct
17 Incorrect 22 ms 364 KB Output isn't correct
18 Incorrect 18 ms 332 KB Output isn't correct
19 Incorrect 103 ms 460 KB Output isn't correct
20 Incorrect 88 ms 460 KB Output isn't correct