답안 #641250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641250 2022-09-16T09:05:12 Z lto5 Med (COCI22_med) C++14
50 / 50
15 ms 376 KB
#include<bits/stdc++.h>
using namespace std;

string s[505];
int b[505][10];
int tot[505];
int n;
int idx[505];

bool cmp (const int& x, const int& y) {
  if (tot[x] != tot[y])
    return tot[x] > tot[y];
  return s[x] < s[y];
}

int find_best (int cur_idx) {
  tot[cur_idx] += 500;
  sort(idx + 1, idx + 1 + n, cmp);
  tot[cur_idx] -= 500;
  for (int i = 1; i <= n; i++) {
    if (idx[i] == cur_idx) {
      return i;
    }
  }

}

int find_worst (int cur_idx) {
  for (int i = 1; i <= n; i++) {
    if (i != cur_idx)
      tot[i] += 500;
  }
  sort(idx + 1, idx + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    if (i != cur_idx)
      tot[i] -= 500;
  }
  for (int i = 1; i <= n; i++) {
    if (idx[i] == cur_idx) {
      return i;
    }
  }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int j = 1; j <= 5; j++) {
      cin >> b[i][j];
      tot[i] += b[i][j];
    }
    idx[i] = i;
  }

  for (int i = 1; i <= n; i++) {
//    iota(idx + 1, idx + 1 + n, 1);
//    for (int j = 1; j <= n; j++)
//      cout << idx[j] << " ";
//    cout << "done" << endl;
    cout << find_best(i) << " " << find_worst(i) << '\n';
  }

  return 0;
}

Compilation message

Main.cpp: In function 'int find_best(int)':
Main.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
   26 | }
      | ^
Main.cpp: In function 'int find_worst(int)':
Main.cpp:43:1: warning: control reaches end of non-void function [-Wreturn-type]
   43 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 10 ms 348 KB Output is correct
6 Correct 11 ms 376 KB Output is correct
7 Correct 7 ms 340 KB Output is correct
8 Correct 15 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct