답안 #859062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859062 2023-10-09T15:44:57 Z NaimSS Gift (IZhO18_nicegift) C++17
0 / 100
813 ms 70788 KB
#include <bits/stdc++.h>
#include <iostream>
// #define int long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v)),v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
// std::mt19937_64 rng64((int) std::chrono::steady_clock::now().time_since_epoch().count());
std::mt19937 rng(
  
//  (int) std::chrono::steady_clock::now().time_since_epoch().count()
   1239010
);
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
//inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
    b%=m;
    ll ans = 1;
    for (; e; b = b * b % m, e /= 2)
        if (e & 1) ans = ans * b % m;
    return ans;
}
// debug:
template<class T>void print_vector(vector<T> &v){
    rep(i,0,sz(v))cout<<v[i]<<" \n"[i==sz(v)-1];
}
void dbg_out() {cerr << endl; }
template<typename Head, typename ... Tail> void dbg_out(Head H,Tail... T){
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__), cerr << endl
#else
#define dbg(...) 42
#endif
//

const int N = 1e6 + 100;
ll a[N];

const ll inf = (ll)1e18 + 9;
ll mult(ll a,ll b){
	if(a > inf/b)return inf;
	return a*b;
}

int32_t main(){
    fastio;
	int n,k;
	cin >> n >> k;
	ll sum=0;
	rep(i,0,n){
		cin >> a[i];
		sum += a[i];
	}
	if(sum%k){
		cout << -1 << endl;
		return 0;
	}
	vector<pair<ll,vi> > res;

	ll divi = sum/k;
	vector<vector<pll>> nv;
	int pt=0;
	while(pt < n){
		ll need = divi;
		vector<pll> here;
		while(need){
			ll put = min(a[pt], need);
			if(a[pt] > divi){
				cout << -1 << endl;
				return 0;
			}
			a[pt] -= put;
			need -= put;
			here.pb(pll(put , pt));
			if(!a[pt])pt++;
		}
		nv.pb(here);
	}
	for(auto &v : nv)reverse(all(v));
	ll put = 0;
	while(divi > 0){
		ll mn = inf;

		for(auto &v : nv){
			mn = min(mn,v.back().ff);
			dbg(v.back().ff, mn);
		}
		divi -= mn;
		dbg(divi);
		if(divi < 0)return 0;
		vi here;
		for(auto &v : nv){
			here.pb(v.back().ss);
			v.back().ff -= mn;
			if(!v.back().ff)v.pop_back();
		}
		res.pb({mn, here});
	}
 

	rep(i,0,n)assert(a[i]==0);
	// cout << "ok" << endl;
	// return 0;


	cout << sz(res) << endl;

	for(auto [X,v] : res){
		cout << X << " ";
		for(auto id : v)cout << id<<" ";
		cout << endl;
	}

	// math -> gcd it all
    // Did you swap N,M? N=1?
}

Compilation message

nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:58:18: warning: statement has no effect [-Wunused-value]
   58 | #define dbg(...) 42
      |                  ^~
nicegift.cpp:112:4: note: in expansion of macro 'dbg'
  112 |    dbg(v.back().ff, mn);
      |    ^~~
nicegift.cpp:58:18: warning: statement has no effect [-Wunused-value]
   58 | #define dbg(...) 42
      |                  ^~
nicegift.cpp:115:3: note: in expansion of macro 'dbg'
  115 |   dbg(divi);
      |   ^~~
nicegift.cpp:106:5: warning: unused variable 'put' [-Wunused-variable]
  106 |  ll put = 0;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 813 ms 70788 KB Integer 0 violates the range [1, 1000000]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -