結果
| 問題 | No.3795 Circular railway |
| ユーザー |
|
| 提出日時 | 2026-11-12 15:33:39 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 486 ms / 2,000 ms |
| + 139µs | |
| コード長 | 1,259 bytes |
| 記録 | |
| コンパイル時間 | 2,626 ms |
| コンパイル使用メモリ | 354,428 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-11-13 22:07:45 |
| 合計ジャッジ時間 | 8,486 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#line 1 "lib/core.hpp"
// Library and Editor Setting is here: https://github.com/Nihonielse/competitive-library
#ifndef CORE_FILE
#define CORE_FILE
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, s) for (int i = s; i < n; i++)
#define vall(v) v.begin(), v.end()
constexpr int INF = 1 << 30;
constexpr int NEG_INF = -INF;
constexpr ll LINF = 1ll << 62;
constexpr ll NEG_LINF = -LINF;
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T>
using min_priority_queue = priority_queue<T,vector<T>,greater<T>>;
#endif
#line 2 "codes/A.cpp"
int main(){
ll n,q,s,t,c;
cin>>n>>q>>s>>t>>c;
s--; t--;
if(s>t)t+=n;
while(q--){
int u,v;
cin>>u>>v;
u--; v--;
if(u==v){
cout<<0<<endl;
continue;
}
if(u>v)v+=n;
if(t-s<=c){
cout<<v-u<<endl;
}else{
if(u<=s&&t<=v){
cout<<s-u+v-t+c<<endl;
}else if(u<=s+n&&t+n<=v){
cout<<s+n-u+v-t-n+c<<endl;
}else{
cout<<v-u<<endl;
}
}
}
}