COFO::Round #707

Problem A : Alexey and Train

Point

Design

Big O(time)

Big O(memory)

Code

#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define r_rep(i, a, b) for(int i=(a); i>(b); i--)
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int n;
vector<int> a, b, t;
void input(){
    cin >> n;
    a.clear(); b.clear(); t.clear();
    a.resize(n+1); b.resize(n+1); t.resize(n+1);
    rep(i, 1, n+1) cin >> a[i] >> b[i];
    rep(i, 1, n+1) cin >> t[i];
}
void solve(){
    input();
    int ans = 0;
    rep(i, 1, n+1){
        ans += (t[i] + a[i] -b[i-1]);
        if(i == n) break;
        int leave = (b[i] - a[i])/2;
        if((b[i] - a[i]) %2) leave++;
        ans = max(b[i], ans + leave);
    }
    cout << ans << '\n';
}
int main(){
    //freopen("input.txt", "r", stdin);
    int tc; cin >> tc;
    while(tc--){
        solve();
    }
    return 0;
}

Problem B : Napoleon Cake

Point

Design

Big O(time)

Big O(memory)

Code

#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define r_rep(i, a, b) for(int i=(a); i>(b); i--)
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;


int n;
vector<int> a;
void solve(){
    cin >> n;
    a.clear(); a.resize(n+2);
    rep(i, 1, n+1){
        int x;
        cin >> x;
        if(x == 0) continue;
        int mx = max(((i+1) - x), 1);
        a[mx] ++;
        a[i+1] --;
        
    }
    int cnt = 0;
    vector<int> ans;
    rep(i, 1, n+1){
        cnt += a[i];
        if(cnt > 0) ans.push_back(1);
        else ans.push_back(0);
    }
    rep(i, 0, ans.size()){
        cout << ans[i] <<" ";
    }
    cout << '\n';
    
}
int main(){
    //freopen("input.txt", "r", stdin);
    int tc; cin >> tc;
    while(tc--){
        solve();
    }
    return 0;
}

Problem C : Going Home

Point

Design

Big O(time)

Big O(memory)

Code

#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define r_rep(i, a, b) for(int i=(a); i>(b); i--)
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
typedef long long ll;
using namespace std;

struct point {int id; int val;};

int n;
vector<point> a;
bool cmp(const point x, const point y){
    return x.val < y.val;
}

const ll maxN = 5e6 + 100;
//map<int, pair<int,int> > mp;
vector<pair<int, int>>res(maxN, make_pair(-1, -1));
void input(){
    a.clear();
    cin >> n;
    a.resize(n);
    rep(i, 0, n){ cin >> a[i].val; a[i].id = i; }
    sort(a.begin(), a.end(), cmp);
}
void solve(){
    input();
    
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int sum = a[i].val + a[j].val;
            if(a[i].id != res[sum].first && a[i].id != res[sum].second && a[j].id != res[sum].first & a[j].id != res[sum].second){
                if(res[sum].first == -1){
                    res[sum] = { a[i].id, a[j].id};
                    continue;
                }
                cout << "YES\n";
                cout << res[sum].first +1 << " " << res[sum].second + 1 << " " << a[i].id+1 << " " << a[j].id+1 << '\n';
                return ;
            }
        }
    }
    cout << "NO\n";
}
int main(){
    //freopen("input.txt", "r", stdin);
    int tc; tc = 1;
    while(tc--){
        solve();
    }
    return 0;
}