# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
182074 | Ruxandra985 | Toll (BOI17_toll) | C++14 | 549 ms | 113660 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
map <int,int> rmq[20][50010];
map <int , pair <int,int> > mp;
int lg[50010] , step[50010];
deque <pair <int,int> > dq;
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int k , n , m , o , x , y, z, i , j , p , len , elem , nod , nr , nrr;
fscanf (fin,"%d%d%d%d",&k,&n,&m,&o);
for (i=1;i<=m;i++){
fscanf (fin,"%d%d%d",&x,&y,&z);
rmq[0][x][y] = z;
}
for (i=2;i<=n;i++)
lg[i] = 1 + lg[i/2];
for (p=1;(1<<p) <= n/k;p++){
for (i=0;i<=n;i++){
if (i / k + (1 << p) <= n / k){ /// e ok
for (j = (i / k + (1 << p)) * k ; j < (i / k + (1 << p) + 1) * k; j++){
rmq[p][i][j] = INF;
for (x = (i / k + (1 << (p-1))) * k ; x < (i / k + (1 << (p-1)) + 1) * k; x++){
if (rmq[p-1][i][x] && rmq[p-1][x][j])
rmq[p][i][j] = min(rmq[p][i][j] , rmq[p-1][i][x] + rmq[p-1][x][j]);
}
}
}
else break;
}
}
for (;o;o--){
fscanf (fin,"%d%d",&x,&y);
if (x / k == y / k){
fprintf (fout,"-1");
continue;
}
len = (y / k) - (x / k);
elem = 0;
while (len){
step[++elem] = lg[len];
len -= (1 << lg[len]);
}
dq.push_back(make_pair(x , 1));
mp[x] = make_pair(o , 0); /// frecventa + cost sa ajungi
mp[y].second = INF;
while (!dq.empty()){
nod = dq.front().first;
nr = dq.front().second;
nrr = step[nr];
dq.pop_front();
if (nr == elem+1)
continue;
mp[nod].first = -o;
for (j = (nod / k + (1 << nrr)) * k ; j < (nod / k + (1 << nrr) + 1) * k; j++){
if (rmq[nrr][nod][j] && ((mp[j].first != o && mp[j].first != -o) || mp[j].second > mp[nod].second + rmq[nrr][nod][j])){
mp[j].second = mp[nod].second + rmq[nrr][nod][j];
if (mp[j].first != o){ /// nu e ACUM in deque
mp[j].first = o;
dq.push_back(make_pair(j , nr + 1));
}
}
}
}
if (mp[y].second == INF)
fprintf (fout,"-1\n");
else fprintf (fout,"%d\n",mp[y].second);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |