Submission #530192

# Submission time Handle Problem Language Result Execution time Memory
530192 2022-02-24T18:58:42 Z FelipeH Teams (CEOI11_tea) C++14
0 / 100
471 ms 42208 KB
#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);
      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);
  int lastId = -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

tea.cpp: In function 'int main()':
tea.cpp:55: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]
   55 |     for(int j = 0;j<teams.size();j++){
      |                   ~^~~~~~~~~~~~~
tea.cpp:38:25: warning: variable 'canForm' set but not used [-Wunused-but-set-variable]
   38 |   int lastId = -1; bool canForm = true;
      |                         ^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 23756 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23756 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 23756 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 23872 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 23792 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 25204 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 25300 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 347 ms 38064 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 449 ms 42208 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 471 ms 41588 KB Expected integer, but "forming" found
2 Halted 0 ms 0 KB -