# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
135704 | khsoo01 | Toll (BOI17_toll) | C++11 | 119 ms | 17836 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int s, n, m, o;
struct way {
int t[5][5];
way() {
for(int i=0;i<5;i++) {
for(int j=0;j<5;j++) {
t[i][j] = inf;
}
}
}
way operator + (way T) {
way ret;
for(int i=0;i<s;i++) {
for(int j=0;j<s;j++) {
for(int k=0;k<s;k++) {
ret.t[i][j] = min(ret.t[i][j], t[i][k]+T.t[k][j]);
}
}
}
return ret;
}
};
struct segtree {
way val[144444];
int lim;
void init () {
for(lim = 1; lim <= n/s; lim <<= 1);
}
void update (int S, int E, int V) {
val[lim+S/s].t[S%s][E%s] = V;
}
void buildup () {
for(int i = lim; --i; ) {
val[i] = val[2*i] + val[2*i+1];
}
}
int query (int S, int E) {
if(S == E) return 0;
if(S/s >= E/s) return inf;
way ra, rb, ret;
for(int i=0;i<s;i++) {
ra.t[i][i] = rb.t[i][i] = 0;
}
int SS = lim + S/s, SE = lim + E/s - 1;
while(SS <= SE) {
if(SS%2 == 1) {ra = ra + val[SS]; SS++;}
if(SE%2 == 0) {rb = val[SE] + rb; SE--;}
SS >>= 1; SE >>= 1;
}
ret = ra + rb;
return ret.t[S%s][E%s];
}
} seg;
int main()
{
scanf("%d%d%d%d",&s,&n,&m,&o);
seg.init();
for(int i=1;i<=m;i++) {
int A, B, C;
scanf("%d%d%d",&A,&B,&C);
seg.update(A, B, C);
}
seg.buildup();
while(o--) {
int S, E;
scanf("%d%d",&S,&E);
int ret = seg.query(S,E);
printf("%d\n",ret == inf ? -1 : ret);
}
}
컴파일 시 표준 에러 (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... |