| Task: | Hotels |
| Sender: | |
| Submission time: | 2017-10-17 20:51:07 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.05 s | details |
| #2 | ACCEPTED | 0.07 s | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | TIME LIMIT EXCEEDED | -- | details |
| #6 | ACCEPTED | 0.04 s | details |
| #7 | ACCEPTED | 0.07 s | details |
| #8 | ACCEPTED | 0.09 s | details |
| #9 | ACCEPTED | 0.20 s | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | ACCEPTED | 0.07 s | details |
| #12 | ACCEPTED | 0.35 s | details |
| #13 | ACCEPTED | 0.03 s | details |
Code
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf=1e9;
int r[111];
int m[111];
int has(map<int, int> d, int t){
for (auto it=d.begin();it!=d.end();it++){
int lp=(*it).F+(t-(*it).S-1);
auto nit=it;
nit++;
int up=(*nit).F-(t-(*nit).S-1);
lp=max(lp, (*it).F-1);
up=min(up, (*nit).F+1);
if (lp+1<up){
return lp+1;
}
}
return inf;
}
void solve(){
int f,e;
cin>>f>>e;
map<int, vector<int> > es;
map<int, int> d;
for (int i=0;i<e;i++){
cin>>r[i]>>m[i];
for (int j=0;;j++){
int x=j*m[i]+r[i];
if (x>=f) break;
es[x].push_back(i);
}
}
priority_queue<pair<int, int> > dij;
dij.push({0, 0});
while (!dij.empty()){
auto t=dij.top();
dij.pop();
int x=t.S;
int dd=-t.F;
assert(x==0||es.count(x));
if (d.count(x)) continue;
d[x]=dd;
for (int ev:es[x]){
if (x+m[ev]<f){
dij.push({-dd, x+m[ev]});
}
if (x-m[ev]>=0){
dij.push({-dd, x-m[ev]});
}
}
auto it=es.upper_bound(x);
if (it!=es.end()){
int nx=(*it).F;
assert(nx>x);
dij.push({-(dd+(nx-x)), nx});
}
if (it!=es.begin()) {
it--;
if (it!=es.begin()){
it--;
int nx=(*it).F;
assert(nx<x);
dij.push({-(dd+(x-nx)), nx});
}
}
}
if (d.count(f-1)==0){
d[f-1]=f-1;
}
int mi=0;
int ma=f;
pair<int, int> ans={0, 0};
while (mi<=ma){
int mid=(mi+ma)/2;
int h=has(d, mid);
if (h<inf){
ans={mid, h};
mi=mid+1;
}
else{
ma=mid-1;
}
}
cout<<ans.F<<" "<<ans.S<<'\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int tcs;
cin>>tcs;
for (int tc=0;tc<tcs;tc++){
solve();
}
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 11 25 1 0 20 25 1 0 19 ... |
| correct output |
|---|
| 10 10 9 9 499999999 499999999 999999998 999999998 999999999 999999999 ... |
| user output |
|---|
| 10 10 9 9 499999999 499999999 999999998 999999998 999999999 999999999 ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 65 11 1 3 5 11 5 2 5 ... |
| correct output |
|---|
| 5 5 5 10 5 9 5 9 5 10 ... |
| user output |
|---|
| 5 5 5 10 5 9 5 9 5 10 ... |
Test 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 55 8 12 0 8 1 8 2 8 ... |
| correct output |
|---|
| 1 1 1 1 2 2 1 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 135 7 5 1 2 1 6 4 7 ... |
| correct output |
|---|
| 2 2 2 2 1 1 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 135 7 5 0 2 1 6 4 7 ... |
| correct output |
|---|
| 1 1 1 1 2 2 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 95 6 0 4 0 6 2 3 4 ... |
| correct output |
|---|
| 5 5 3 3 5 5 7 7 1 1 ... |
| user output |
|---|
| 5 5 3 3 5 5 7 7 1 1 ... |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 95 7 1 0 2 5 1 1 2 ... |
| correct output |
|---|
| 1 1 2 2 1 1 2 2 1 1 ... |
| user output |
|---|
| 1 1 2 2 1 1 2 2 1 1 ... |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 95 7 3 0 2 1 7 2 6 ... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 1 1 1 1 1 ... |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 95 7 2 0 2 1 2 6 2 ... |
| correct output |
|---|
| 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 1 1 1 1 1 ... |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 20 1000000000 100 594150 1000129 656679 999660 155808 1000433 ... |
| correct output |
|---|
| 44179 765964436 76578 186966148 47657 794974629 85198 224959980 127364 764952716 ... |
| user output |
|---|
| (empty) |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 55 8 5 6 8 2 8 7 8 ... |
| correct output |
|---|
| 7 7 4 4 7 7 4 4 9 9 ... |
| user output |
|---|
| 7 7 4 4 7 7 4 4 9 9 ... |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 100 10000000 1 502894 966242 20000000 2 1669915 1712967 ... |
| correct output |
|---|
| 1303821 9999999 2870329 19999999 3838029 29999999 3455687 39999999 2433171 5877033 ... |
| user output |
|---|
| 1303821 9999999 2870329 19999999 3838029 29999999 3455687 39999999 2433171 5877033 ... |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 1 21 3 0 3 0 2 1 2 |
| correct output |
|---|
| 0 0 |
| user output |
|---|
| 0 0 |
