답안 #639039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639039 2022-09-08T11:22:41 Z inksamurai Hokej (COCI17_hokej) C++17
0 / 120
123 ms 20612 KB
#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3RhsN1z ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

signed main(){
_3RhsN1z;
	int m,n;
	cin>>m>>n;
	using T=pair<int,pii>;
	vec(T) a(n);
	vec(pii) ina(n);
	rep(i,n){
		cin>>a[i].fi>>a[i].se.fi;
		a[i].se.se=i;
		ina[i]={a[i].fi,a[i].se.fi};
	}
	sort(a.begin(),a.end());
	const int si=6;
	int k=0;
	vec(vec(pii)) rbts(si);
	while(k<si){
		int now=0;
		while(now<m){
			assert(sz(a));
			T u=a.back();
			a.pop_back();
			int need=min(u.se.fi,m-now);
			assert(need>0);
			rbts[k].pb({need,u.se.se});
			u.se.fi-=need;
			now+=need;
			if(u.se.fi>0){
				a.pb(u);
			}
		}
		k+=1;
	}
	int res=0;
	rep(i,si){
		for(auto p:rbts[i]){
			res+=p.fi*ina[p.se].fi;
		}
	}
	cout<<res<<"\n";
	while(1){
		bool fnd=0;
		pii p={-1,-1};
		rep(i,si){
			rep(j,sz(rbts[i])){
				if(rbts[i][j].fi<m){
					p={i,j};
					break;
				}
			}
		}
		rep(i,si){
			int tm=0;
			rep(j,sz(rbts[i])-1){
				if(rbts[i][j+1].fi==m){
					assert(p.fi!=-1 and p.se!=-1);
					swap(rbts[p.fi][p.se],rbts[i][j]);
					fnd=1;
					break;
				}
			}
		}
		if(!fnd) break;
	}
	cout<<res<<"\n";
	rep(i,si){
		cout<<rbts[i][0].se+1<<" ";
	}
	cout<<"\n";
	vec(T) pns;
	rep(i,si){
		int tm=0;
		rep(j,sz(rbts[i])-1){
			tm+=rbts[i][j].fi;
			pns.pb({tm,{rbts[i][j].se,rbts[i][j+1].se}});
		}
	}
	sort(pns.begin(),pns.end());
	cout<<sz(pns)<<"\n";
	for(auto tp:pns){
		cout<<tp.fi<<" "<<tp.se.fi+1<<" "<<tp.se.se+1<<"\n";
	}
}

Compilation message

hokej.cpp: In function 'int main()':
hokej.cpp:73:8: warning: unused variable 'tm' [-Wunused-variable]
   73 |    int tm=0;
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 OK 0 ms 212 KB Checker has crashed
2 OK 2 ms 468 KB Checker has crashed
3 Incorrect 6 ms 1316 KB Expected int32, but "299047561386" found
4 OK 1 ms 340 KB Checker has crashed
5 OK 3 ms 852 KB Checker has crashed
6 OK 1 ms 468 KB Checker has crashed
7 OK 2 ms 596 KB Checker has crashed
8 OK 25 ms 4708 KB Checker has crashed
9 Incorrect 122 ms 20364 KB Expected int32, but "298674474813" found
10 Incorrect 123 ms 20612 KB Expected int32, but "297203184231" found