답안 #583130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583130 2022-06-24T21:27:23 Z evening_g Poi (IOI09_poi) C++11
0 / 100
73 ms 65536 KB
/**
 * @file poi.cpp
 * @brief https://oj.uz/problem/view/IOI09_poi
 * @version 0.1
 * @date 2022-06-24
 * 
 * 
 */

#include<bits/stdc++.h>

using namespace std;

int find_rank(const vector<int> &v, const int &target) {
    int index = 0;
    while(v[index] != target) index++;
    return index + 1;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    // DEFINE VARIABLES

    int n, t, p, x;

    cin >> n >> t >> p;

    vector< vector<int> > contestants(n, {t, 0}); // tasks solved by each contestant
    vector<int> tasks(t, n);    // worth of each task
    vector<int> score(n, 0);    // score of each contestant

    // READ DATA

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < t; j++) {
            cin >> contestants[i][j];
            // if this user solved this task
            if (contestants[i][j] == 1) {
                // the worth of the task decreases with each contestant that solves it
                tasks[j] --;
            }
        }        
    }
    
    // PROCESS
    //calculate score of each contestant
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < t; j++) {
            if (contestants[i][j] == 1) {
                // the worth of the task decreases with each contestant that solves it
                score[i] += tasks[j];
            } 
        }
    }
    
    // get philip schore
    int philip_score = score[p + 1];

    // sort by score
    sort(score.begin(), score.end(), greater<int>());

    // as there can't be contestats with the same score
    // we use philip's score to find its rank

    cout << philip_score << " " << find_rank(score, philip_score) << '\n';
       
    return 0;
}

Compilation message

poi.cpp: In function 'int main()':
poi.cpp:29:18: warning: unused variable 'x' [-Wunused-variable]
   29 |     int n, t, p, x;
      |                  ^
poi.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
poi.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 65536 KB Execution killed with signal 9
2 Runtime error 65 ms 65536 KB Execution killed with signal 9
3 Runtime error 70 ms 65536 KB Execution killed with signal 9
4 Runtime error 65 ms 65536 KB Execution killed with signal 9
5 Runtime error 57 ms 65536 KB Execution killed with signal 9
6 Runtime error 57 ms 65536 KB Execution killed with signal 9
7 Runtime error 60 ms 65536 KB Execution killed with signal 9
8 Runtime error 60 ms 65536 KB Execution killed with signal 9
9 Runtime error 57 ms 65536 KB Execution killed with signal 9
10 Runtime error 72 ms 65536 KB Execution killed with signal 9
11 Runtime error 67 ms 65536 KB Execution killed with signal 9
12 Runtime error 65 ms 65536 KB Execution killed with signal 9
13 Runtime error 54 ms 65536 KB Execution killed with signal 9
14 Runtime error 65 ms 65536 KB Execution killed with signal 9
15 Runtime error 58 ms 65536 KB Execution killed with signal 9
16 Runtime error 57 ms 65536 KB Execution killed with signal 9
17 Runtime error 73 ms 65536 KB Execution killed with signal 9
18 Runtime error 55 ms 65536 KB Execution killed with signal 9
19 Runtime error 59 ms 65536 KB Execution killed with signal 9
20 Runtime error 59 ms 65536 KB Execution killed with signal 9