結果
| 問題 |
No.3072 Speedrun Query
|
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2025-03-21 22:54:01 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 382 ms / 2,500 ms |
| コード長 | 1,647 bytes |
| コンパイル時間 | 932 ms |
| コンパイル使用メモリ | 25,984 KB |
| 実行使用メモリ | 7,328 KB |
| 最終ジャッジ日時 | 2025-03-21 22:54:07 |
| 合計ジャッジ時間 | 6,335 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 21 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:56:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | scanf("%d %d %d", &n, &ka, &kb);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:60:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
60 | scanf("%d", &a[i]);
| ^~~~~~~~~~~~~~~~~~
main.c:65:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
65 | scanf("%d", &b[i]);
| ^~~~~~~~~~~~~~~~~~
main.c:76:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
76 | scanf("%d", &q);
| ^~~~~~~~~~~~~~~
main.c:80:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
80 | scanf("%d %d", &s, &t);
| ^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
int abs(int n)
{
if (n < 0)
n *= -1;
return n;
}
int n, ka, kb;
int a[300005], b[300005];
int id_a(int v)
{
int min, mid, max;
min = -1;
max = ka;
while (max - min > 1)
{
mid = (max + min) / 2;
if (a[mid] < v)
min = mid;
else
max = mid;
}
if (min < 0)
return a[max];
else if (max == ka)
return a[min];
else if (v - a[min] < a[max] - v)
return a[min];
else
return a[max];
}
int id_b(int v)
{
int min, mid, max;
min = -1;
max = kb;
while (max - min > 1)
{
mid = (max + min) / 2;
if (b[mid] < v)
min = mid;
else
max = mid;
}
if (min < 0)
return b[max];
else if (max == kb)
return b[min];
else if (v - b[min] < b[max] - v)
return b[min];
else
return b[max];
}
int main()
{
scanf("%d %d %d", &n, &ka, &kb);
int i, j;
for (i = 0; i < ka; i++)
{
scanf("%d", &a[i]);
a[i]--;
}
for (i = 0; i < kb; i++)
{
scanf("%d", &b[i]);
b[i]--;
}
int dist = abs(a[0] - b[0]);
for (i = 0; i < ka; i++)
{
j = id_b(a[i]);
if (dist > abs(a[i] - j))
dist = abs(a[i] - j);
}
int q, s, t;
scanf("%d", &q);
int ans;
for (; q > 0; q--)
{
scanf("%d %d", &s, &t);
s--;
t--;
ans = t - s;
i = id_a(s);
j = id_a(t);
if (ans > abs(s - i) + abs(t - j))
ans = abs(s - i) + abs(t - j);
i = id_b(s);
j = id_b(t);
if (ans > abs(s - i) + abs(t - j))
ans = abs(s - i) + abs(t - j);
i = id_a(s);
j = id_b(t);
if (ans > abs(s - i) + abs(t - j) + dist)
ans = abs(s - i) + abs(t - j) + dist;
i = id_b(s);
j = id_a(t);
if (ans > abs(s - i) + abs(t - j) + dist)
ans = abs(s - i) + abs(t - j) + dist;
printf("%d\n", ans);
}
return 0;
}
pengin_2000