# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
48855 | 2018-05-19T10:29:41 Z | mrtsima22 | Gift (IZhO18_nicegift) | C++17 | 41 ms | 2652 KB |
#include <bits/stdc++.h> using namespace std; #define lo long const int lmax=1999999999; const long long lmx=1999999999999999999; int n,k,p; long long a[100003],sum; set<pair<int,int> >s; vector<vector<int> > ans; int main(){std::ios::sync_with_stdio(false); cin>>n>>k; for(int i=1;i<=n;i++) { cin>>a[i]; sum=sum+a[i]; } bool ok=1; for(int i=2;i<=n;i++) { ok=ok&(a[i]==a[i-1]); } if(!(sum<=1000000||ok)){ cout<<-1<<endl;return 0;} if(sum%k!=0){ cout<<-1<<endl;return 0;} for(int i=1;i<=n;i++) { s.insert(make_pair(a[i],i)); } p=1; if(ok){ p=sum/(n*k/__gcd(n,k)); } while(s.size()) { int t=0; vector<int>v; while(s.size()&&t<k) { int u=(*(s.begin())).second; s.erase(s.begin()); v.push_back(u); a[u]-=p; t++; } if(t!=k){cout<<-1<<endl;return 0; } for(int i=0;i<v.size();i++) { if(a[i]>0) { s.insert(make_pair(a[i],i)); } } ans.push_back(v); } cout<<ans.size()<<endl; for(int i=0;i<ans.size();i++) { cout<<p<<endl; for(int j=0;j<ans[i].size();j++) { cout<<ans[i][j]<<" "; } cout<<endl; } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 252 KB | Jury has the answer but participant has not |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 252 KB | Jury has the answer but participant has not |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 252 KB | Jury has the answer but participant has not |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 41 ms | 2652 KB | Jury has the answer but participant has not |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 252 KB | Jury has the answer but participant has not |
2 | Halted | 0 ms | 0 KB | - |