답안 #378952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378952 2021-03-17T07:55:32 Z wiwiho Gift (IZhO18_nicegift) C++14
30 / 100
652 ms 74704 KB
#include <bits/stdc++.h>

#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define printv(a, b) { \
    for(auto pv : a) b << pv << " "; \
    b << "\n"; \
}

using namespace std;

typedef long long ll;

using pll = pair<ll, ll>;
using pii = pair<int, int>;

const ll MAX = 1LL << 60;

ostream& operator<<(ostream& o, pll p){
    return o << '(' << p.F << ',' << p.S << ')';
}

ll iceil(ll a, ll b){
    return (a + b - 1) / b;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;

    vector<ll> pos(n + 1), a(n + 1);
    ll sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
    }

    if(sum % k){
        cout << "-1\n";
        return 0;
    }
    ll len = sum / k;

    ll now = 0;
    vector<ll> t;
    for(int i = 1; i <= n; i++){
        if(a[i] > len){
            cout << "-1\n";
            return 0;
        }
        now += a[i];
        pos[i] = (now - 1) % len;
        t.eb(pos[i]);
    }

    sort(t.begin(), t.end());
    t.resize(unique(t.begin(), t.end()) - t.begin());
    len = t.size();

    vector<vector<int>> ans(len);
    int j = -1;
    ll total = 0;
    for(int i = 1; i <= n; i++){
        int id = lower_bound(t.begin(), t.end(), pos[i]) - t.begin();
        for(j = (j + 1) % len; ; j = (j + 1) % len){
            ans[j].eb(i);
            total++;
            if(j == id) break;
        }
    }
    cout << len << "\n";
    int lst = -1;
    for(int i = 0; i < len; i++){
        cout << t[i] - lst << " " ;
        assert(ans[i].size() == k);
        printv(ans[i], cout);
        lst = t[i];
    }

    return 0;
}

Compilation message

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from nicegift.cpp:1:
nicegift.cpp: In function 'int main()':
nicegift.cpp:80:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |         assert(ans[i].size() == k);
      |                ~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 512 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 34 ms 4628 KB n=50000
12 Correct 57 ms 4460 KB n=50000
13 Correct 1 ms 392 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 512 KB n=623
16 Correct 1 ms 492 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 512 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 34 ms 4628 KB n=50000
12 Correct 57 ms 4460 KB n=50000
13 Correct 1 ms 392 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 512 KB n=623
16 Correct 1 ms 492 KB n=973
17 Correct 2 ms 492 KB n=989
18 Correct 1 ms 492 KB n=563
19 Correct 2 ms 492 KB n=592
20 Correct 5 ms 492 KB n=938
21 Correct 2 ms 492 KB n=747
22 Correct 9 ms 492 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Incorrect 652 ms 74704 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 512 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 34 ms 4628 KB n=50000
12 Correct 57 ms 4460 KB n=50000
13 Correct 1 ms 392 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 512 KB n=623
16 Correct 1 ms 492 KB n=973
17 Correct 2 ms 492 KB n=989
18 Correct 1 ms 492 KB n=563
19 Correct 2 ms 492 KB n=592
20 Correct 5 ms 492 KB n=938
21 Correct 2 ms 492 KB n=747
22 Correct 9 ms 492 KB n=991
23 Incorrect 652 ms 74704 KB Taken too much stones from the heap
24 Halted 0 ms 0 KB -