Submission #530165

# Submission time Handle Problem Language Result Execution time Memory
530165 2022-02-24T18:05:48 Z FelipeH Teams (CEOI11_tea) C++14
0 / 100
2500 ms 36172 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1000000 + 10;
pair<int,int> v[MAXN];
vector<int> t[MAXN];

int main(){
  int n; 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 ans = 0;
  for(int i = 1;i<=n;i++){
    int cur = i, have = 1;
    int canForm = false;
    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[i].push_back(v[j].second);
        }
        i = cur;
        canForm = true;
        break;
      }
    }
    if(canForm) continue;
    int smallest = 0;
    for(int j = 1;j<i;j++){
      if(t[j].size() + 1 < v[i].first) continue;
      if(smallest == 0 || t[smallest].size() > t[j].size()){
        smallest = j;
      }
    }
    // printf("inserting %d to team %d\n", i, smallest);
    t[smallest].push_back(v[i].second);
  }
  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:39:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |       if(t[j].size() + 1 < v[i].first) continue;
      |          ~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Incorrect 12 ms 23756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 23756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 23884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 23824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 636 ms 25236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 778 ms 25488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2587 ms 33068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2566 ms 35716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2507 ms 36172 KB Time limit exceeded
2 Halted 0 ms 0 KB -