NC26013. 榜单
描述
给定一场CCPC比赛的题目数量和提交列表,请你输出终榜。
榜单的格式见输出和样例
根据比赛规则,榜单有以下要求:
输入描述
第一行一个数字 n,表示这场比赛有 n 道题目,题目的标号从 A开始。
接下来若干行,每行格式形如:`时间 题号 结果 队名`,表示一条提交,提交按时间顺序排列。
其中,时间形如`HH:MM`,并且时间一定小于`05:00`。
题号为单独的一个大写字母。
结果属于集合 { `Accepted`, `Wrong Answer`, `Time Limit Exceeded`, `Compile Error`, `Memory Limit Exceeded`, `Output Limit Exceeded`, `Runtime Error`, `Presentation Error` }。
队名为一个含有空格、大写和小写字母的字符串,队名长度不超过 50。
输入以一行 `GAME OVER!` 结尾,表示比赛结束。
数据保证最多有5000条提交记录。
输出描述
输出的榜单有 n+4 栏,每栏之间间隔 2 个空格。
Rank 一栏的宽度为 4 个字符,表示该队伍的排名
Who 一栏的宽度为所有显示在榜单上的队伍名字的最长长度,表示该队伍的名字
Solved 一栏宽度为 6 个字符,显示每个队伍通过题目的数量
Penalty 一栏宽度为 7 个字符,按要求显示每队罚时
接下来是题目栏,每个题目栏的宽度均为 3 个字符,按要求显示`+`或`-`,表示每个队伍通过题目的情况
每一栏的第一行为这一栏的名称,其中,Who 需左对齐,其他栏需右对齐。
题目栏的名称为题目的标号
接下来若干行,按顺序输出每个队伍的信息,每栏的信息需右对齐。
队伍按照通过题目数量排名,如果两队通过题目数量相等,罚时少的队伍排名靠前。
注意,如果出现题数和罚时均相等的队伍,则按照队名的字典序排序,同时`Rank`一栏的值需相等。第一个与他们排名不相等的队伍的排名可以是绝对排名或相对排名。例如前五个队伍的排名分别为1,2,3,3,3,则第六个队伍的绝对排名为5,相对排名为4,你的程序只需要按照一种方式输出即可,即1,2,3,3,3,5和1,2,3,3,3,4两种输出均正确,但是你需要保证你的程序对于所有输入均按照一种方式输出。
示例1
输入:
4 00:01 B Wrong Answer University of Deep Dark Fantasy 00:01 B Accepted University of Deep Dark Fantasy 00:01 C Accepted University of Deep Dark Fantasy 00:01 D Accepted University of Deep Dark Fantasy 00:11 A Accepted Deep Dark Institude of Fantasy 00:13 C Wrong Answer Banana University 01:01 C Wrong Answer Banana University 01:11 C Wrong Answer Banana University 02:01 C Runtime Error Deep Dark Institude of Fantasy 02:10 C Accepted Deep Dark Institude of Fantasy 02:30 A Accepted University of Deep Dark Fantasy 02:50 D Accepted Bon Sha Ka La Ka Higher School of Economics 02:51 C Accepted Bon Sha Ka La Ka Higher School of Economics 02:52 B Accepted Bon Sha Ka La Ka Higher School of Economics 02:53 A Accepted Bon Sha Ka La Ka Higher School of Economics 02:55 A Runtime Error University Van Billy 02:59 B Compile Error University Van Banana GAME OVER!
输出:
Rank Who Solved Penalty A B C D 1 University of Deep Dark Fantasy 4 173 + +1 + + 2 Bon Sha Ka La Ka Higher School of Economics 4 686 + + + + 3 Deep Dark Institude of Fantasy 2 161 + +1 4 Banana University 0 0 -3 4 University Van Billy 0 0 -1
C++(g++ 7.5.0) 解法, 执行用时: 10ms, 内存消耗: 680K, 提交时间: 2022-10-03 23:48:21
#include<iostream> #include<map> #include<vector> #include<cstdio> #include<algorithm> using namespace std; struct node { int Rank; string Who; int Solved=0; int Penalty=0; int ac_sign[15]={0};//标记是否通过 int tijiao_num[15]={0};//提交次数 }; int calc(string s) { int xiaoshi=0,fenzhong=0; xiaoshi = (s[0]-'0')*10+(s[1]-'0'); fenzhong = (s[3]-'0')*10+(s[4]-'0'); return xiaoshi*60+fenzhong; } bool cmp(node x,node y) { if(x.Solved!=y.Solved)return x.Solved>y.Solved; else if(x.Penalty!=y.Penalty)return x.Penalty<y.Penalty; else return x.Who<y.Who; } int main() { int n; cin>>n; int i,j,k,l,m; string s; map<string,node>mp; map<char,int>r; vector<node> v; r['A']=8; r['W']=12;r['T']=19;r['C']=13;r['M']=21;r['O']=21; r['R']=13;r['P']=18; getchar(); while(1) { getline(cin,s); if(s=="GAME OVER!") { break; } if(s[8]!='C') { string team=""; for(i=r[s[8]]+8+1;i<s.length();i++)team+=s[i]; // cout<<team<<endl; 可以获取team mp[team].Who=team; // cout<<team<<endl; int time_now; time_now=calc(s); if(s[8]=='A') { if(mp[team].ac_sign[s[6]-'A']==0) { mp[team].ac_sign[s[6]-'A']=1; mp[team].Solved+=1; mp[team].Penalty+=mp[team].tijiao_num[s[6]-'A']*20+time_now; } } else { if(mp[team].ac_sign[s[6]-'A']==0) { mp[team].tijiao_num[s[6]-'A']+=1; } } } } for(auto i=mp.begin();i!=mp.end();i++) { v.push_back(i->second); } // cout<<v.size()<<endl; sort(v.begin(),v.end(),cmp); int ma=v[0].Who.length(); int flag=1; for(i=0;i<v.size();i++) { if(i==0) { v[i].Rank=flag; } else { if((v[i].Penalty==v[i-1].Penalty)&&(v[i].Solved==v[i-1].Solved)) { v[i].Rank=flag; } else { flag++; v[i].Rank=flag; } } if(v[i].Who.length()>ma)ma=v[i].Who.length(); } printf("Rank Who"); for(i=0;i<ma-1;i++)cout<<" "; printf("Solved Penalty"); for(i=0;i<n;i++) { cout<<" "<<(char)(i+'A'); } cout<<endl; for(i=0;i<v.size();i++) { printf("%4d ",v[i].Rank); for(j=0;j<ma-v[i].Who.length();j++)cout<<" "; cout<<v[i].Who<<" "; printf("%6d %7d ",v[i].Solved,v[i].Penalty); for(j=0;j<n;j++) { if(v[i].ac_sign[j]==1) { if(v[i].tijiao_num[j]!=0) { cout<<" +"<<v[i].tijiao_num[j]; } else { cout<<" +"; } } else { if(v[i].tijiao_num[j]!=0) { cout<<" -"<<v[i].tijiao_num[j]; } else { cout<<" "; } } if(j!=n-1) cout<<" "; } if(i!=v.size()-1) cout<<endl; } }
Python3 解法, 执行用时: 45ms, 内存消耗: 3704K, 提交时间: 2021-05-30 15:47:02
from collections import defaultdict dic = {"A": 17, "W": 21, "T": 28, "C": 22, "M": 30, "O": 30, "R": 22, "P": 27} N = int(input()) class data: def __init__(self): self.ac = 0 self.submits = [0] * N self.finished = [False] * N self.penalty = 0 def __str__(self): return f"{self.ac} {self.penalty} {self.submits}" teams = defaultdict(data) while True: cur = input() if cur[0] == "G": break state = cur[8] if state == "C": continue name = cur[dic[state] :] curTeam = teams[name] question = ord(cur[6]) - 65 if state == "A": if not curTeam.finished[question]: curTeam.finished[question] = True time = int(cur[:2]) * 60 + int(cur[3:5]) curTeam.penalty += time + curTeam.submits[question] * 20 curTeam.ac += 1 else: curTeam.submits[question] += 1 board = list(teams.items()) def cmp(li): name: str = li[0] dat: data = li[1] return -dat.ac, dat.penalty, name board.sort(key=cmp) # for team, t in board: # print(team, t) # print() maxlen = max(len(name) for name in teams.keys()) print("Rank Who" + " " * (maxlen - 3) + " Solved Penalty", end="") for i in range(N): print(" " + chr(i + 65), end="") ranks = 0 for i, (name, dat) in enumerate(board): print() if not (i > 0 and dat.ac == board[i - 1][1].ac and dat.penalty == board[i - 1][1].penalty): ranks += 1 namesp = maxlen - len(name) print("%4d " % ranks + " " * namesp + name + " %6d" % dat.ac + " %7d" % dat.penalty, end="") for i in range(N): if dat.finished[i]: if not dat.submits[i]: res = "+" else: res = "+" + str(dat.submits[i]) else: if not dat.submits[i]: res = "" else: res = "-" + str(dat.submits[i]) print("%5s" % res, end="")
C++(clang++11) 解法, 执行用时: 10ms, 内存消耗: 2280K, 提交时间: 2021-05-03 16:30:18
#include<bits/stdc++.h> #define ll long long #define endl '\n' using namespace std; struct sch{ string mz; int tj[15],sj[15],js,zt; bool zq[15],sc,bj; }q[10005]; int n,zs,hh,mm,mxl,la; string s,h,m; char t; bool pd=0,ce=0; unordered_map<string,int> mp; bool comp(sch a,sch b) { if(a.sc==b.sc) { if(a.js==b.js) { if(a.zt==b.zt) return a.mz<b.mz; else return a.zt<b.zt; } else return a.js>b.js; } else return a.sc>b.sc; } int main() { //ios::sync_with_stdio(false); //cin.tie(0); cout.tie(0); scanf("%d",&n); while(cin>>s&&s!="GAME") { pd=0; ce=0; h=s.substr(0,2),m=s.substr(3,2); //时间 hh=stoi(h); mm=stoi(m); getchar(); cin>>t; //题号 cin>>s; if(s=="Accepted") pd=1; else { if(s=="Compile") ce=1; cin>>s; if(s=="Limit") cin>>s; } getline(cin,s); if(ce) continue; int l=s.size(); mxl=max(mxl,l); if(!mp[s]) { mp[s]=++zs; q[mp[s]].mz=s; } int x=mp[s],tx=t-64; if(!ce) q[x].sc=1; if(!pd&&!ce) { q[x].tj[tx]++; q[x].sj[tx]+=20; } if(pd) { q[x].sj[tx]+=mm+hh*60; if(!q[x].zq[tx]) { q[x].js++; q[x].zt+=q[x].sj[tx]; } q[x].zq[tx]=1; } } sort(q+1,q+zs+1,comp); printf("Rank Who"); for(int i=1;i<=max(0,mxl-4);i++) printf(" "); printf(" Solved Penalty"); for(int i=1;i<=n;i++) printf(" %c",i+64); printf("\n"); for(int i=1;i<=zs;i++) { if(!q[i].sc) break; if(q[i].zt==q[i-1].zt&&q[i].js==q[i-1].js&&i!=1) printf("%4d",la); else printf("%4d",++la); int l=q[i].mz.size(),u; u=1+mxl-l; for(int j=1;j<=u;j++) printf(" "); cout<<q[i].mz; printf("%8d%9d",q[i].js,q[i].zt); for(int j=1;j<=n;j++) { if(q[i].zq[j]) { if(q[i].tj[j]==0) printf(" +"); else printf(" +%d",q[i].tj[j]); } else { if(q[i].tj[j]==0) printf(" "); else printf(" -%d",q[i].tj[j]); } } printf("\n"); } return 0; }