Submission #306401

#TimeUsernameProblemLanguageResultExecution timeMemory
306401colazcyHokej (COCI17_hokej)C++17
120 / 120
249 ms41976 KiB
#include <cstdio> #include <cctype> #include <algorithm> #include <vector> using namespace std; const int maxn = 5e5 + 100; typedef long long ll; inline int read(){ int x = 0;char c = getchar(); while(!isdigit(c))c = getchar(); while(isdigit(c))x = x * 10 + c - '0',c = getchar(); return x; } struct node{ int v,tim,id; bool operator < (const node &rhs)const{ if(v != rhs.v)return v > rhs.v; return tim > rhs.tim; } }val[maxn]; struct seg{ int l,r,v,d; }ans[maxn]; int m,n,tot; ll out; vector<int> vec[maxn]; struct mpair{int x,y,z;}; vector<mpair> tmp; int main(){ m = read(),n = read(); for(int i = 1;i <= n;i++)val[i].v = read(),val[i].tim = read(),val[i].id = i; sort(val + 1,val + 1 + n); ll sum = 0; for(int i = 1;i <= n;i++){ int beg = sum % m; seg sa = seg{beg + 1,beg + min(val[i].tim,m - beg),val[i].id,val[i].v}; sum += sa.r - sa.l + 1; val[i].tim -= sa.r - sa.l + 1; ans[++tot] = sa; if(sum == 6 * m)break; if(!val[i].tim)continue; seg sb = seg{1,min(val[i].tim,m),val[i].id,val[i].v}; if(sb.r >= beg)ans[tot] = seg{1,m,val[i].id,val[i].v},sum += beg; else ans[++tot] = sb,sum += sb.r - sb.l + 1; if(sum == 6 * m)break; } for(int i = 1;i <= tot;i++) for(int k = ans[i].l;k <= ans[i].r;k++)vec[k].push_back(ans[i].v); for(int i = 1;i <= m;i++) if(vec[i].size() > 6)return -1; for(int i = 1;i <= tot;i++)out += ll(ans[i].r - ans[i].l + 1) * ans[i].d; printf("%lld\n",out); for(unsigned int i = 0;i < 6;i++)printf("%d ",vec[1][i]); printf("\n"); int vis[6]; for(int i = 2;i <= m;i++){ for(int j = 0;j < 6;j++)vis[j] = 0; for(unsigned int j = 0;j < 6;j++){ int flag = 0; for(unsigned int k = 0;k < 6;k++) if(vec[i - 1][j] == vec[i][k]){ flag = 1; break; } if(!flag){ for(unsigned int k = 0;k < 6;k++) if(vec[i - 1][j] != vec[i][k] && !vis[k] && find(vec[i - 1].begin(),vec[i - 1].end(),vec[i][k]) == vec[i - 1].end()){ tmp.push_back(mpair{i - 1,vec[i - 1][j],vec[i][k]}); vis[k] = 1; break; } } } } printf("%d\n",(int)tmp.size()); for(unsigned int i = 0;i < tmp.size();i++){ printf("%d %d %d\n",tmp[i].x,tmp[i].y,tmp[i].z); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...