結果

問題 No.3284 Picnic with Friends
ユーザー hirayuu_yc
提出日時 2025-09-26 19:48:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,693 bytes
コンパイル時間 5,955 ms
コンパイル使用メモリ 200,196 KB
実行使用メモリ 8,596 KB
最終ジャッジ日時 2025-09-26 20:52:53
合計ジャッジ時間 13,448 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int64 N;
    if(!(cin >> N)) return 0;
    vector<int64> S(N);
    for(int i=0;i<N;i++) cin >> S[i];
    int Q; cin >> Q;
    vector<pair<int64,int64>> events(Q);
    for(int i=0;i<Q;i++){
        int64 T,F; cin >> T >> F;
        events[i] = {T, F};
    }

    // 時刻を "半時間単位" (0.5h = 1) で整数化
    vector<pair<int64,int64>> intervals;
    bool has = false;
    int64 cur_s = 0, cur_e = 0; // in halves
    for(auto &ev : events){
        int64 T = ev.first;
        int64 F = ev.second;
        int64 t2 = T * 2;               // event time in halves
        int64 start_dur = 2*F + 1;      // F + 0.5 -> halves
        int64 extend = 2*F;             // extend by F hours -> halves

        if(!has || cur_e <= t2){
            if(has) intervals.emplace_back(cur_s, cur_e);
            cur_s = t2;
            cur_e = t2 + start_dur;
            has = true;
        } else {
            // currently ongoing -> extend end by F hours
            cur_e += extend;
        }
    }
    if(has) intervals.emplace_back(cur_s, cur_e);

    // 各フレンズについて各区間の floor( (length_hours) / S_i )
    // length_hours = (cur_e - cur_s) / 2
    // floor => floor( (length_halves) / (2 * S_i) )
    for(int i=0;i<N;i++){
        int64 s = S[i];
        int64 denom = 2 * s; // safe in 64-bit (s <= 1e12)
        long long ans = 0;
        for(auto &iv : intervals){
            int64 len = iv.second - iv.first; // in halves
            ans += (len / denom);
        }
        cout << ans << '\n';
    }
    return 0;
}
0