QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#435954 | #8793. Toilets | ucup-team3586# | TL | 6ms | 12152kb | C++23 | 1.9kb | 2024-06-08 22:36:46 | 2024-06-08 22:36:46 |
Judging History
answer
//泥の分際で私だけの大切を奪おうだなん
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
#define int long long
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
pair<int,int> ans[1<<18];
int a[1<<18],lst[1<<18];
struct node{int t,p,s,d;}b[1<<18];
bool vis[1<<18];
int n=read(),m=read(),L=read();
int calc(int pid,int tid)
{
int dist=(a[tid]+L-b[pid].p)%L;
if(!b[pid].s) dist=(L-dist)%L;
int sdt=b[pid].t+dist;
int require=max(0ll,lst[tid]-sdt);
return sdt+((require+L-1)/L)*L;
}
int best_match_toliet(int x)
{
int mn=1e18,id=-1;
for(int i=1; i<=m; ++i)
{
int tmp=calc(x,i);
if(tmp<mn) mn=tmp,id=i;
}
return id;
}
int best_match_person(int x)
{
int mn=1e18,id=-1;
for(int i=1; i<=n; ++i) if(!vis[i])
{
int tmp=calc(i,x);
if(tmp<mn) mn=tmp,id=i;
}
// assert(id!=-1);
return id;
}
void Match(int pid,int tid)
{
int dist=(a[tid]+L-b[pid].p)%L;
if(!b[pid].s) dist=(L-dist)%L;
int sdt=b[pid].t+dist;
int require=max(0ll,lst[tid]-sdt);
ans[pid]={a[tid],sdt+((require+L-1)/L)*L};
lst[tid]=sdt+((require+L-1)/L)*L+b[pid].d;
vis[pid]=1;
}
signed main()
{
for(int i=1; i<=m; ++i) a[i]=read(),lst[i]=-1e18;
sort(a+1,a+m+1);
for(int i=1; i<=n; ++i)
b[i].t=read(),b[i].p=read(),
b[i].s=(getchar()=='+'),b[i].d=read();
for(int T=n; T--;)
{
int A=best_match_person(1);
int B=best_match_toliet(A);
int C=best_match_person(B);
while(A!=C)
{
A=C;
B=best_match_toliet(A),
C=best_match_person(B);
}
Match(C,B);
}
for(int i=1; i<=n; ++i)
printf("%lld %lld\n",ans[i].first,ans[i].second);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12048kb
input:
5 3 45 10 20 30 0 0 + 200 2 5 + 10 20 40 - 100 21 16 + 10 50 0 + 22
output:
20 20 10 7 30 30 10 60 10 105
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 10048kb
input:
1 1 1 0 0 0 - 1
output:
0 0
result:
ok 2 number(s): "0 0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 10040kb
input:
5 3 33 3 24 23 12 24 - 9 16 28 - 1 17 27 - 9 19 26 - 5 32 22 - 2
output:
24 12 23 21 3 41 24 21 3 51
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 10112kb
input:
4 5 6 1 3 4 2 0 2 1 + 2 7 3 + 6 9 0 + 9 10 1 - 6
output:
1 2 3 7 0 9 1 10
result:
ok 8 numbers
Test #5:
score: 0
Accepted
time: 6ms
memory: 12152kb
input:
736 30 100500 99382 85511 67593 53450 55531 9959 37170 57546 52666 62342 50707 71285 65933 19874 2092 100255 23965 83091 45652 64171 100128 19518 21445 96069 79781 52642 37943 95321 97569 69154 0 44619 + 7052 2 72499 + 29247 3 53785 - 35614 5 81887 + 64475 7 8561 + 31641 8 95471 - 22654 9 61040 - 44...
output:
53450 310331 95321 22824 53450 338 67593 186711 23965 718911 95321 158 83091 580958 62342 71243 50707 602820 83091 183 2092 375130 96069 552638 100128 541370 64171 5285 50707 288492 45652 795873 2092 284 85511 720931 55531 713428 53450 483192 69154 5302 83091 155808 57546 351069 2092 231938 85511 60...
result:
ok 1472 numbers
Test #6:
score: -100
Time Limit Exceeded
input:
200000 200000 200000 45589 41206 151226 67898 73967 140984 73325 186330 35522 72131 147731 139390 123121 817 198939 98824 55631 84079 28987 108012 22006 143408 11442 195253 179662 189693 142207 99819 103750 166626 140235 140358 148893 170212 14967 98607 193895 19535 87565 166568 179135 11569 109260 ...