結果

問題 No.2700 Please Hack Greedy Solution!
ユーザー inkyamaninkyaman
提出日時 2024-03-29 22:37:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 500 ms
コード長 959 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 123,684 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-29 22:37:29
合計ジャッジ時間 2,086 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'll comp(std::pair<long long int, long long int>&, std::pair<long long int, long long int>&)':
main.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
   26 | }
      | ^

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
#include <tuple>
using namespace std;
using ll = long long;

ll comp(pair<ll,ll> &p1, pair<ll,ll> &p2) {
    auto [vi,wi] = p1;
    auto [vj,wj] = p2;
    if(vi*wj != vj*wi) return vi*wj > vj*wi;
    else wi > wj;
}

int main() {

    vector<pair<ll,ll>> ans;
    ans.push_back({1000,1});


    for(int p = 2; p <= 1000; ++p) {
        sort(ans.begin(),ans.end(),comp);
        ll q = p, G = 0;
        for(auto [vi,wi] : ans) {
            if(wi > q) continue;
            q -= wi;
            G += vi;
        }
        ans.push_back({G+1,p});
    }

    cout << 1000 << " " << 1000 << endl;
    for(auto [vi,wi] : ans) cout << vi << " " << wi << endl;

}

0