Submission #530195

#TimeUsernameProblemLanguageResultExecution timeMemory
530195FelipeHTeams (CEOI11_tea)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 1000000 + 10; pair<int,int> v[MAXN]; vector<int> t[MAXN]; vector<pair<int,int>> teams; int marc[MAXN], ans = 0, n; int addToTeam(int i, int have, int team){ int cur = i; while(cur <= n){ if(v[cur].first > have){ int diff = v[cur].first - have; // printf("difference of %d from %d to desired %d\n",cur,have,v[cur].first); have = v[cur].first; cur += diff; }else{ // printf("forming a team from %d to %d with %d members\n",i,cur,have); 1 ans++; for(int j = i;j<=cur;j++){ t[team].push_back(v[j].second); } teams.push_back(make_pair(have, team)); return cur; } } return -1; } int main(){ cin >> n; for(int i = 1;i<=n;i++){ int val; cin >> val; v[i] = make_pair(val, i); } sort(v + 1, v + n + 1); for(int i = 1;i<=n;i++){ // printf("(%d,%d)\n",v[i].first,v[i].second); } int lastId = n + 1; bool canForm = true; for(int i = 1;i<=n;i++){ int tmp = addToTeam(i, 1, i); if(tmp == -1){ canForm = false; lastId = i; break; }else{ i = tmp; } } for(int i = lastId; i<=n;i++){ marc[v[i].first] = i; } for(int i = lastId; i<=n;i++){ // printf("processing %d\n",i); sort(teams.begin(), teams.end()); for(int j = 0;j<teams.size();j++){ // printf("-trying team %d\n",teams[j].second); int diff = v[i].first - teams[j].first; // printf("--there is %d %d's left and diff = %d\n", marc[v[i].first] - i + 1, v[i].first, diff); if(marc[v[i].first] - i + 1 >= diff){ for(int k = 0;k<=diff && i <= n;k++){ // printf("inserting %d to team %d\n",i,teams[j].second); t[teams[j].second].push_back(v[i].second); teams[j].first++; i++; } break; } } } cout << ans << "\n"; for(int i = 1;i<=n;i++){ int size = t[i].size(); if(size != 0){ cout << size << " "; for(int j = 0;j<size;j++){ cout << t[i][j] << " "; } cout << "\n"; } } return 0; }

Compilation message (stderr)

tea.cpp: In function 'int addToTeam(int, int, int)':
tea.cpp:20:4: error: expected ';' before 'ans'
   20 |   1    ans++;
      |    ^   ~~~
      |    ;
tea.cpp:20:3: warning: statement has no effect [-Wunused-value]
   20 |   1    ans++;
      |   ^
tea.cpp: In function 'int main()':
tea.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int j = 0;j<teams.size();j++){
      |                   ~^~~~~~~~~~~~~