답안 #764902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764902 2023-06-24T06:24:46 Z dxz05 Parkovi (COCI22_parkovi) C++17
30 / 110
99 ms 7236 KB
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
#define BIT(x, i) (((x) >> (i)) & 1)
//#define endl '\n'

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 2e5 + 30;

int n;
int w[N];

vector<int> parks(ll d){
    vector<int> p;

    for (int i = 1; i <= n;){
        ll x = 0;
        int j = i + 1;
        while (j <= n && x + w[j - 1] <= d){
            x += w[j - 1];
            j++;
        }
        j--;

        p.push_back(j);

        x = 0;
        while (j < n && x + w[j] <= d){
            x += w[j];
            j++;
        }

        i = j + 1;
    }

    return p;
}

void solve(){
    int k;
    cin >> n >> k;

    for (int i = 1; i < n; i++) cin >> w[i] >> w[i] >> w[i];

    vector<int> ans;

    ll l = 0, r = 2e15;
    while (l <= r){
        ll m = (l + r) >> 1;

        vector<int> p = parks(m);

        if (p.size() <= k){
            ans = p;
            r = m - 1;
        } else {
            l = m + 1;
        }
    }


    cout << ++r << endl;
    for (int x : ans) cout << x << ' ';

    int x = k - (int) ans.size();
    for (int i = 1; i <= n; i++){
        if (x == 0) break;
        int j = lower_bound(all(ans), i) - ans.begin();
        if (j == ans.size() || ans[j] != i){
            cout << i << ' ';
            x--;
        }
    }

    cout << endl;
}

int main(){
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int test_cases = 1;
//    cin >> test_cases;

    for (int test = 1; test <= test_cases; test++){
        // cout << (solve() ? "YES" : "NO") << endl;
        solve();
    }

#ifdef LOCAL
    cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif

    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:65:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |         if (p.size() <= k){
      |             ~~~~~~~~~^~~~
Main.cpp:81:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         if (j == ans.size() || ans[j] != i){
      |             ~~^~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:91:13: warning: unused variable 'startTime' [-Wunused-variable]
   91 |     clock_t startTime = clock();
      |             ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 936 KB Output is correct
2 Correct 50 ms 964 KB Output is correct
3 Incorrect 44 ms 992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 988 KB Output is correct
2 Correct 41 ms 980 KB Output is correct
3 Correct 40 ms 908 KB Output is correct
4 Correct 39 ms 996 KB Output is correct
5 Correct 78 ms 5888 KB Output is correct
6 Correct 85 ms 2744 KB Output is correct
7 Correct 87 ms 3740 KB Output is correct
8 Correct 48 ms 1032 KB Output is correct
9 Correct 40 ms 1060 KB Output is correct
10 Correct 39 ms 964 KB Output is correct
11 Correct 38 ms 1036 KB Output is correct
12 Correct 99 ms 6016 KB Output is correct
13 Correct 91 ms 7236 KB Output is correct
14 Correct 83 ms 7092 KB Output is correct
15 Correct 46 ms 3928 KB Output is correct
16 Correct 35 ms 3740 KB Output is correct
17 Correct 36 ms 3728 KB Output is correct
18 Correct 38 ms 3924 KB Output is correct
19 Correct 70 ms 7232 KB Output is correct
20 Correct 54 ms 7132 KB Output is correct
21 Correct 50 ms 6200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -