제출 #1336122

#제출 시각아이디문제언어결과실행 시간메모리
1336122retardeLet's Win the Election (JOI22_ho_t3)C++20
61 / 100
2593 ms8472 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()

typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;

int n, k;
const int mxn = 505;
pair<ld, ld> s[mxn]; int can[mxn]; vi canv;

void st(ld &x, ld y) {x = min(x, y);}

ld solve2(int x) {
    // cout << x << " contris " << x + 1 << "total\n";
    vector<vector<ld>> dp(n+1, vector<ld>(n+1, 1e18));
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {continue;}
    
    // j collaboraters
    dp[0][0] = ((ld)s[0].se)/((ld)((ld)x+(ld)1)); if (s[0].fi != 1e16) dp[0][1] = s[0].fi;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < n; j++) {
            // get a col here
            if (s[i].fi != 1e16 && j >= 1) {
                st(dp[i][j], dp[i - 1][j - 1] + (ld)s[i].fi/(ld)(j));
            }

            // dont get col here
            st(dp[i][j], dp[i - 1][j] + (ld)s[i].se/(ld)(x+1)); // use cols
        }
    }

    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j <= n; j++) {
    //         cout << "pos #" << i + 1 << " with " << j << " contris and " << (i+1)-j << " nons: " << dp[i][j] << '\n';
    //     }
    // }

    vector<vector<ld>> smp(n+2, vector<ld>(n+2)); multiset<int> itms;
    for (int i = n - 1; i >= 0; i--) {
        itms.insert(s[i].se);
        int id = 1; int sm = 0;
        for (auto &x : itms) {
            sm += x;
            smp[i][id] = sm;
            // cout << "pos #" << i << " with " << id << " of them: " << smp[i][id] << '\n';
            id++;
        }
    }
    
    // include for 0

    ld ans = 1e18;
    for (int i = 0; i < n; i++) {
        ld c1 = dp[i][x]; // x colls
        ld c2 = 0; if (k > (i + 1)) c2 = (ld)(smp[i + 1][k-(i+1)])/(ld)(x+1);
        // if ((i+1) - x == k) ans = min(ans, c1);
        // else ans = min(ans, c1 + c2);
        // cout << k << " " << i + 1 << '\n';
        // cout << "pos #" << i + 1 << " c1,c2 " << c1 << " " << c2 << '\n';
        ans = min(ans, c1 + c2);
    }
    // cout << ans << "\n\n";
    return ans;
}

inline void solve() {
    cin >> n >> k;
    fill(s, s + mxn, mp(1e18, 1e18)); vi ass;
    for (int i = 0; i < n; i++) {
        cin >> s[i].se >> s[i].fi; 
        ass.pb(s[i].se); 
        if (s[i].fi != -1) {canv.pb(i); can[i]=1;}
        else s[i].fi = 1e16;
    }
    sort(s, s + mxn);
    sort(all(ass));
    
    ld ans = 1e18;

    ld sm = 0; for (int i = 0; i < k; i++) sm += ass[i];
    ans = min(ans, sm);

    for (int c = 1; c <= canv.size(); c++) {
        // how many contributor
        ans = min(ans, solve2(c));
    }

    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

signed main() {
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    //setIO();

    int t = 1;
    if (tc) {
        cin >> t;
    }

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

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:118:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:119:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...