提出 #64228328
ソースコード 拡げる
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
using namespace std;
#define MOD 998244353
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
template <u32 Mod> class ModInt {
using Self = ModInt<Mod>;
static_assert(Mod <= std::numeric_limits<i32>::max());
public:
ModInt(i64 value = 0) {
if (value < 0) {
value_ = (Mod - (-value % Mod)) % Mod;
} else {
value_ = value % Mod;
}
}
ModInt(const Self& other) : value_(other.value_) {}
operator i32() const {
return value_;
}
operator i64() const {
return value_;
}
Self operator+(const Self& other) const {
Self res(*this);
res += other;
return res;
}
Self operator-(const Self& other) const {
Self res(*this);
res -= other;
return res;
}
Self operator*(const Self& other) const {
Self res(*this);
res *= other;
return res;
}
Self operator/(const Self& other) const {
Self res(*this);
res /= other;
return res;
}
Self operator-() const {
Self res(0);
res -= *this;
return res;
}
Self pow(i64 power) const {
Self ret(1), p(*this);
if (power < 0) {
power *= -1;
p = p.inv();
}
for (i64 i = 0; (1 << i) <= power; ++i) {
if ((power >> i) & 1) ret *= p;
p *= p;
}
return ret;
}
Self& operator+=(const Self& other) {
value_ += other.value_;
if (value_ >= Mod) value_ -= Mod;
return *this;
}
Self& operator-=(const Self& other) {
value_ += Mod - other.value_;
if (value_ >= Mod) value_ -= Mod;
return *this;
}
Self& operator*=(const Self& other) {
value_ = (u32)(((u64)value_ * other.value_) % Mod);
return *this;
}
Self& operator/=(const Self& other) {
*this *= other.inv();
return *this;
}
Self inv() const {
if (value_ < inv_tbl_.size()) return inv_tbl_[value_];
if (Mod - value_ < inv_tbl_.size()) return Mod - inv_tbl_[Mod - value_];
else return pow(Mod - 2);
}
private:
u32 value_;
static const std::vector<Self> inv_tbl_;
};
template <u32 Mod>
std::vector<ModInt<Mod>> create_inv_tbl_(u32 n) {
std::vector<ModInt<Mod>> res;
res.reserve(n + 1);
res.push_back(0);
res.push_back(1);
for (u32 i = 2; i <= n; ++i) {
// MOD / i == 0
// MOD // i + (MOD % i) / i == 0
// 1 / i == -(MOD // i) / (MOD % i)
res.push_back(res[Mod % i] * ModInt<Mod>(Mod - (Mod / i)));
}
return res;
}
template <u32 Mod>
const std::vector<ModInt<Mod>> ModInt<Mod>::inv_tbl_ = create_inv_tbl_<Mod>(1000000);
template <class T, u32 Mod>
ModInt<Mod> operator+(T x, ModInt<Mod> y) {
return ModInt<Mod>(x) + y;
}
template <class T, u32 Mod>
ModInt<Mod> operator-(T x, ModInt<Mod> y) {
return ModInt<Mod>(x) - y;
}
template <class T, u32 Mod>
ModInt<Mod> operator*(T x, ModInt<Mod> y) {
return ModInt<Mod>(x) * y;
}
template <class T, u32 Mod>
ModInt<Mod> operator/(T x, ModInt<Mod> y) {
return ModInt<Mod>(x) / y;
}
template <class T, u32 Mod>
ModInt<Mod> operator+(ModInt<Mod> x, T y) {
return x + ModInt<Mod>(y);
}
template <class T, u32 Mod>
ModInt<Mod> operator-(ModInt<Mod> x, T y) {
return x - ModInt<Mod>(y);
}
template <class T, u32 Mod>
ModInt<Mod> operator*(ModInt<Mod> x, T y) {
return x * ModInt<Mod>(y);
}
template <class T, u32 Mod>
ModInt<Mod> operator/(ModInt<Mod> x, T y) {
return x / ModInt<Mod>(y);
}
typedef ModInt<MOD> mint;
int N;
i64 W[202020];
int L[202020], R[202020];
int Q;
i64 ls[404040], rs[404040];
const i64 INFT = 1LL << 60LL;
i64 solve(int s, int t) {
if (R[s] <= L[t] || R[t] <= L[s]) {
return 0;
}
i64 ret = INFT;
ret = min(ret, ls[max(R[s], R[t])]);
ret = min(ret, rs[min(L[s], L[t])]);
if (R[s] > L[t]) {
ret = min(ret, ls[R[s]] + rs[L[t]]);
}
if (L[s] < R[t]) {
ret = min(ret, rs[L[s]] + ls[R[t]]);
}
return ret;
}
int main()
{
scanf("%d", &N);
for (int i = 0; i < N; ++i) scanf("%lld", W + i);
for (int i = 0; i < N; ++i) {
scanf("%d%d", L + i, R + i);
--L[i];
}
for (int i = 0; i <= 2 * N; ++i) ls[i] = rs[i] = INFT;
for (int i = 0; i < N; ++i) {
ls[L[i]] = min(ls[L[i]], W[i]);
rs[R[i]] = min(rs[R[i]], W[i]);
}
for (int i = 2 * N - 1; i >= 0; --i) ls[i] = min(ls[i], ls[i + 1]);
for (int i = 1; i <= 2 * N; ++i) rs[i] = min(rs[i], rs[i - 1]);
scanf("%d", &Q);
for (;Q--;) {
int s, t;
scanf("%d%d", &s, &t);
--s; --t;
i64 ans = solve(s, t);
if (ans > INFT / 2) ans = -1;
else {
ans += W[s] + W[t];
}
printf("%lld\n", ans);
}
return 0;
}
提出情報
コンパイルエラー
Main.cpp: In function ‘int main()’:
Main.cpp:210:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
210 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
Main.cpp:211:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
211 | for (int i = 0; i < N; ++i) scanf("%lld", W + i);
| ~~~~~^~~~~~~~~~~~~~~
Main.cpp:213:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
213 | scanf("%d%d", L + i, R + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:226:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
226 | scanf("%d", &Q);
| ~~~~~^~~~~~~~~~
Main.cpp:230:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
230 | scanf("%d%d", &s, &t);
| ~~~~~^~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
700 / 700 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
example0.txt, example1.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 000.txt |
AC |
106 ms |
13032 KiB |
| 001.txt |
AC |
90 ms |
13144 KiB |
| 002.txt |
AC |
88 ms |
13160 KiB |
| 003.txt |
AC |
105 ms |
13212 KiB |
| 004.txt |
AC |
107 ms |
13048 KiB |
| 005.txt |
AC |
107 ms |
13276 KiB |
| 006.txt |
AC |
108 ms |
13240 KiB |
| 007.txt |
AC |
107 ms |
13032 KiB |
| 008.txt |
AC |
83 ms |
13028 KiB |
| 009.txt |
AC |
64 ms |
7352 KiB |
| 010.txt |
AC |
63 ms |
9512 KiB |
| 011.txt |
AC |
64 ms |
10732 KiB |
| 012.txt |
AC |
31 ms |
4484 KiB |
| 013.txt |
AC |
54 ms |
9800 KiB |
| 014.txt |
AC |
114 ms |
13140 KiB |
| 015.txt |
AC |
112 ms |
13208 KiB |
| 016.txt |
AC |
111 ms |
13208 KiB |
| 017.txt |
AC |
111 ms |
13036 KiB |
| 018.txt |
AC |
110 ms |
13244 KiB |
| 019.txt |
AC |
111 ms |
13048 KiB |
| 020.txt |
AC |
111 ms |
13128 KiB |
| 021.txt |
AC |
113 ms |
12944 KiB |
| 022.txt |
AC |
117 ms |
13052 KiB |
| 023.txt |
AC |
112 ms |
13116 KiB |
| example0.txt |
AC |
1 ms |
3668 KiB |
| example1.txt |
AC |
1 ms |
3772 KiB |