Submission #479273

#TimeUsernameProblemLanguageResultExecution timeMemory
479273Spartan117Poi (IOI09_poi)C++14
100 / 100
921 ms24388 KiB
#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; struct contestant { vector<int> responses; int id; int numOfQuestions; int score; contestant(const int &i) { id = i; numOfQuestions = 0; score = 0; } }; vector<contestant> contestants; map<int, int> marksperTask; int n{}, t{}, p{}; void inputContestants() { cin >> n >> t >>p; int response{}; for(int i{}; i<n; i++) { contestants.push_back(contestant(i+1)); for(int j{}; j<t; j++) { cin >> response; contestants[i].responses.push_back(response); if(response==0) marksperTask[j+1]++; } int qnums{}; for(int response: contestants[i].responses) qnums+=response; contestants[i].numOfQuestions = qnums; } for(int i{}; i<n; i++) { for(int j{}; j<t; j++) if (contestants[i].responses[j]==1) contestants[i].score += marksperTask[j+1]; } } bool compareContestants(contestant &contestant1, contestant &contestant2) { if (contestant1.score > contestant2.score) return true; else if (contestant1.score == contestant2.score) { if (contestant1.numOfQuestions > contestant2.numOfQuestions) return true; else if (contestant1.numOfQuestions == contestant2.numOfQuestions) return (contestant1.id < contestant2.id); else return false; } else return false; } void displayOutput() { int pScore{}, pRank{}; for (int i{}; i<n; i++) if (contestants[i].id == p) { pRank = i+1; pScore = contestants[i].score; break; } cout << pScore << ' ' << pRank << '\n'; } int main() { inputContestants(); sort(contestants.begin(), contestants.end(), compareContestants); displayOutput(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...