답안 #537313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537313 2022-03-15T00:45:00 Z cig32 Gift (IZhO18_nicegift) C++17
30 / 100
691 ms 121152 KB
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { // read int128
  int x; cin >> x; return (ll)x;
}
long long bm(long long b, long long p) {
  if(p==0) return 1 % MOD;
  long long r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
long long inv(long long b) { 
  return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) { 
  long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
  ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() { 
  for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD);
}
void solve(int tc) {
  int n, k;
  cin >> n >> k;
  priority_queue<pair<int, int> > pq;
  int a[n+1];
  for(int i=1; i<=n; i++) {
    cin >> a[i];
    pq.push({a[i], i});
  }
  if(k == n) {
    for(int i=1; i<n; i++) {
      if(a[i] != a[i+1]) {
        cout << "-1\n"; return;
      }
    }
    cout << "1\n";
    cout << a[1];
    for(int i=1; i<=n; i++) cout << " " << i;
    cout << "\n";
    return;
  }
  int lim = 3000000 / k;
  vector<int> op(k + 1); // op[0]: value, op[1] to op[k]: indices
  vector<vector<int> > all;
  for(int i=1; i<=lim; i++) {
    if(pq.top().first == 0) break;
    vector<pair<int, int> > v;
    for(int j=0; j<k; j++) {
      v.push_back(pq.top());
      pq.pop();
    }
    int weight = v[k-1].first - pq.top().first + (pq.top().first == 0 ? 0 : 1);
    for(int j=0; j<k; j++) {
      pq.push({v[j].first - weight, v[j].second});
    }
    op[0] = weight;
    for(int j=1; j<=k; j++) op[j] = v[j-1].second;
    all.push_back(op);
  }
  if(pq.top().first > 0) {
    cout << "-1\n"; return;
  }
  cout << all.size() << "\n";
  for(vector<int>x: all) {
    for(int vw: x) cout << vw << " ";
    cout << "\n";
  }
}
int32_t main(){
  precomp();
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1876 KB n=4
2 Correct 3 ms 1876 KB n=3
3 Correct 240 ms 83968 KB n=3
4 Correct 2 ms 1876 KB n=4
5 Correct 254 ms 84168 KB n=4
6 Correct 2 ms 1876 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1876 KB n=4
2 Correct 3 ms 1876 KB n=3
3 Correct 240 ms 83968 KB n=3
4 Correct 2 ms 1876 KB n=4
5 Correct 254 ms 84168 KB n=4
6 Correct 2 ms 1876 KB n=2
7 Correct 2 ms 1876 KB n=5
8 Correct 280 ms 84008 KB n=8
9 Correct 6 ms 2516 KB n=14
10 Correct 5 ms 2268 KB n=11
11 Correct 25 ms 5316 KB n=50000
12 Correct 31 ms 5988 KB n=50000
13 Correct 16 ms 3404 KB n=10
14 Correct 26 ms 4580 KB n=685
15 Correct 27 ms 4872 KB n=623
16 Correct 16 ms 3484 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1876 KB n=4
2 Correct 3 ms 1876 KB n=3
3 Correct 240 ms 83968 KB n=3
4 Correct 2 ms 1876 KB n=4
5 Correct 254 ms 84168 KB n=4
6 Correct 2 ms 1876 KB n=2
7 Correct 2 ms 1876 KB n=5
8 Correct 280 ms 84008 KB n=8
9 Correct 6 ms 2516 KB n=14
10 Correct 5 ms 2268 KB n=11
11 Correct 25 ms 5316 KB n=50000
12 Correct 31 ms 5988 KB n=50000
13 Correct 16 ms 3404 KB n=10
14 Correct 26 ms 4580 KB n=685
15 Correct 27 ms 4872 KB n=623
16 Correct 16 ms 3484 KB n=973
17 Correct 25 ms 4532 KB n=989
18 Correct 13 ms 2772 KB n=563
19 Correct 20 ms 3284 KB n=592
20 Correct 20 ms 3292 KB n=938
21 Correct 16 ms 2912 KB n=747
22 Correct 19 ms 3128 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Incorrect 691 ms 121152 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1876 KB n=4
2 Correct 3 ms 1876 KB n=3
3 Correct 240 ms 83968 KB n=3
4 Correct 2 ms 1876 KB n=4
5 Correct 254 ms 84168 KB n=4
6 Correct 2 ms 1876 KB n=2
7 Correct 2 ms 1876 KB n=5
8 Correct 280 ms 84008 KB n=8
9 Correct 6 ms 2516 KB n=14
10 Correct 5 ms 2268 KB n=11
11 Correct 25 ms 5316 KB n=50000
12 Correct 31 ms 5988 KB n=50000
13 Correct 16 ms 3404 KB n=10
14 Correct 26 ms 4580 KB n=685
15 Correct 27 ms 4872 KB n=623
16 Correct 16 ms 3484 KB n=973
17 Correct 25 ms 4532 KB n=989
18 Correct 13 ms 2772 KB n=563
19 Correct 20 ms 3284 KB n=592
20 Correct 20 ms 3292 KB n=938
21 Correct 16 ms 2912 KB n=747
22 Correct 19 ms 3128 KB n=991
23 Incorrect 691 ms 121152 KB Jury has the answer but participant has not
24 Halted 0 ms 0 KB -