QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#621 | #415556 | #8230. Submissions | ushg8877 | ushg8877 | Failed. | 2024-05-20 23:46:48 | 2024-05-20 23:46:48 |
Details
Extra Test:
Accepted
time: 14ms
memory: 91932kb
input:
1 13 M J 1 rejected F Y 3 accepted F Y 16 accepted T O 20 rejected P B 27 rejected G A 35 rejected U L 48 accepted Y R 51 rejected F Y 70 rejected F Y 75 accepted Q X 78 accepted X P 89 accepted A R 98 rejected
output:
2 F M
result:
ok 1 test cases ok. (1 test case)
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#415556 | #8230. Submissions | ushg8877 | AC ✓ | 323ms | 105004kb | C++14 | 3.4kb | 2024-05-20 23:43:14 | 2024-05-20 23:51:32 |
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=1e5+5;
map<string,int> mp;
int n,m,vid,gl,pre;
struct team{
string name;
ll fs[26],tot;int cnt;bool ps[26],ans;
vector<pair<int,bool> > sub[26];
void init(){
memset(fs,0,sizeof(fs));
memset(ps,0,sizeof(ps));
ans=false;tot=cnt=0;
for(int i=0;i<26;i++) sub[i].clear();
}
void upd(int id){
tot-=fs[id]*ps[id];
vid-=(cnt>0);
cnt-=ps[id];
fs[id]=ps[id]=0;
for(auto i:sub[id])if(!ps[id]){
if(i.second==1){
fs[id]+=i.first;
ps[id]=true;
}else fs[id]+=20;
}
tot+=fs[id]*ps[id];
cnt+=ps[id];
vid+=(cnt>0);
gl=min(35,(int)ceil(vid*0.1));
}
}gp[MAXN];
bool operator >(team &x,team &y){
if(x.cnt!=y.cnt) return x.cnt>y.cnt;
return x.tot<y.tot;
}
bool operator >=(team &x,team &y){
if(x.cnt!=y.cnt) return x.cnt>y.cnt;
return x.tot<=y.tot;
}
void solve(){
cin>>m;
for(int i=1;i<=m;i++) gp[i].init();
n=vid=pre=gl=0;mp.clear();
for(int i=1;i<=m;i++){
string team,pro,sta;ll tim;
cin>>team>>pro>>tim>>sta;
if(!mp.count(team)){
mp[team]=++n;
gp[n].name=team;
}
int id=mp[team],pid=pro[0]-'A';
gp[id].sub[pid].push_back(MP(tim,sta[0]=='a'));
}
for(int i=1;i<=n;i++) for(int j=0;j<26;j++) gp[i].upd(j);
sort(gp+1,gp+n+1,[&](team &x,team &y){return x>y;});
// cout<<"Valid Team: "<<vid<<' '<<n<<'\n';
// cout<<"Goal: "<<gl<<'\n';
// for(int i=1;i<=n;i++)
// cout<<"Rank "<<i<<": "<<gp[i].name<<' '<<gp[i].tot<<' '<<gp[i].cnt<<'\n';
for(int i=1;i<=n;i++) if(gp[i]>=gp[gl]) gp[i].ans=true;
auto upd=[&](int sp){
// cout<<"Check sp "<<sp<<' '<<gl<<'\n';
if(gl==0) return;
int l=0,r=n,mid=0,cnt=0;
while(l<r){
mid=(l+r+1)>>1;
cnt=mid-1-(sp<mid)+(gp[sp]>gp[mid]);
if(cnt<gl) l=mid;
else r=mid-1;
}
if(l==0) l=sp;
else{
cnt=l-1-(sp<l)+(gp[sp]>gp[l]);
if(cnt<gl-1&&gp[l]>=gp[sp]&&gp[sp]>=gp[l+1]) l=sp;
}
if(gp[sp]>=gp[l]){
// cout<<"Special "<<sp<<' '<<l<<" is OK!\n";
gp[sp].ans=true;
}
int spl=l;
l=1,r=n;
while(l<r){
if(r==sp) r--;
mid=(l+r+1)>>1;
if(mid==sp){
if(mid>l+1) mid--;
else mid++;
}
if(gp[mid]>=gp[spl]) l=mid;
else r=mid-1;
if(r==sp) r--;
}
// cout<<"Here "<<spl<<' '<<l<<'\n';
// cout<<"Detail: "<<gp[sp].cnt<<' '<<gp[sp].tot<<'\n';
pre=max(pre,l);
};
for(int i=1;i<=n;i++){
for(int j=0;j<26;j++){
bool fa=false,fr=false;
for(auto &k:gp[i].sub[j]){
// cout<<"Get! "<<' '<<k.first<<' '<<k.second<<'\n';
if(k.second==0&&fr==false){
fr=true;
k.second=1;
gp[i].upd(j);
upd(i);
k.second=0;
gp[i].upd(j);
}else if(k.second==1&&fa==false){
fa=true;
k.second=0;
gp[i].upd(j);
upd(i);
k.second=1;
gp[i].upd(j);
}
}
fr=false;
for(int k=gp[i].sub[j].size()-1;k>=0;k--)
if(gp[i].sub[j][k].second==0&&fr==false){
fr=true;
gp[i].sub[j][k].second=1;
gp[i].upd(j);
upd(i);
gp[i].sub[j][k].second=0;
gp[i].upd(j);
}
}
}
for(int i=1;i<=pre;i++) gp[i].ans=true;
int cnt=0;
for(int i=1;i<=n;i++) cnt+=gp[i].ans;
cout<<cnt<<'\n';
for(int i=1;i<=n;i++) if(gp[i].ans) cout<<gp[i].name<<' ';
cout<<'\n';
}
int main(){
ios::sync_with_stdio(false);
// freopen("Otomachi_Una.in","r",stdin);
// freopen("Otomachi_Una.out","w",stdout);
int _;cin>>_;
while(_--) solve();
return 0;
}