답안 #530193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530193 2022-02-24T18:59:11 Z FelipeH Teams (CEOI11_tea) C++14
0 / 100
485 ms 42180 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;
      |                         ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23756 KB Integer parameter [name=s_i] equals to 2, violates the range [1, 1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 23756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 23824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 23844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 25248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 25340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 317 ms 38308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 438 ms 42180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 485 ms 41572 KB Output isn't correct
2 Halted 0 ms 0 KB -