답안 #530194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530194 2022-02-24T19:02:00 Z FelipeH Teams (CEOI11_tea) C++14
0 / 100
472 ms 42128 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 = 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

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:28: warning: variable 'canForm' set but not used [-Wunused-but-set-variable]
   38 |   int lastId = n + 1; bool canForm = true;
      |                            ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23796 KB Output is correct
2 Incorrect 14 ms 23756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 23884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 25264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 25304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 327 ms 38240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 447 ms 42128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 472 ms 41616 KB Output isn't correct
2 Halted 0 ms 0 KB -