problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03109 | Python | Runtime Error | from datetime import date
dt = date.fromisoformat(input().replace("/", "-"))
th = date.fromisoformat("2019-04-30")
if dt <= th:
print("Heisei")
else:
print("TBD")
| y, m, d = map(int, input().split("/"))
if y < 2019:
print("Heisei")
elif y == 2019 and m < 5:
print("Heisei")
else:
print("TBD")
| replace | 0 | 5 | 0 | 4 | 0 | |
p03109 | Python | Runtime Error | A, B, C = map(int, input().split(" "))
ymd = tuple(map(int, input().split("/")))
if ymd <= (2019, 4, 30):
print("Heisei")
else:
print("TBD")
| ymd = tuple(map(int, input().split("/")))
if ymd <= (2019, 4, 30):
print("Heisei")
else:
print("TBD")
| delete | 0 | 1 | 0 | 0 | ValueError: invalid literal for int() with base 10: '2019/04/30' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03109/Python/s758016076.py", line 1, in <module>
A, B, C = map(int, input().split(' '))
ValueError: invalid literal for int() with base 10: '2019/04/30'
|
p03109 | Python | Runtime Error | date = input()
date = date.replace("/", "")
if date <= 20190430:
print("Heisei")
else:
print("TBD")
| date = input()
date = int(date.replace("/", ""))
if date <= 20190430:
print("Heisei")
else:
print("TBD")
| replace | 2 | 3 | 2 | 3 | TypeError: '<=' not supported between instances of 'str' and 'int' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03109/Python/s278452814.py", line 4, in <module>
if date <= 20190430:
TypeError: '<=' not supported between instances of 'str' and 'int'
|
p03109 | Python | Runtime Error | s = map(int, input().split("/"))
print("Heisei" if s <= 20190430 else "TBD")
| s = int(input().replace("/", ""))
print("Heisei" if s <= 20190430 else "TBD")
| replace | 0 | 1 | 0 | 1 | TypeError: '<=' not supported between instances of 'map' and 'int' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03109/Python/s969500454.py", line 2, in <module>
print("Heisei" if s <= 20190430 else "TBD")
TypeError: '<=' not supported between instances of 'map' and 'int'
|
p03109 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
if (S.at(5) == '1') {
cout << "TBD" << endl;
}
else if (S.at(6) == '1' || S.at(6) == '2' || S.at(6) == '3' ||
S.at(6) == '4') {
cout << "Heisei" << endl;
}
else {
cout << "TBD" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(5) == '1') {
cout << "TBD" << endl;
}
else if (S.at(6) == '1' || S.at(6) == '2' || S.at(6) == '3' ||
S.at(6) == '4') {
cout << "Heisei" << endl;
}
else {
cout << "TBD" << endl;
}
}
| insert | 5 | 5 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 5) >= this->size() (which is 0)
|
p03109 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f;
while (scanf("%d/%d/%d", &a, &b, &c)) {
if (b <= 4) {
cout << "Heisei" << endl;
} else {
cout << "TBD" << endl;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f;
scanf("%d/%d/%d", &a, &b, &c);
if (b <= 4) {
cout << "Heisei" << endl;
} else {
cout << "TBD" << endl;
}
return 0;
}
| replace | 4 | 10 | 4 | 10 | TLE | |
p03109 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
string year = s.substr(0, 4);
string month = s.substr(5, 2);
string day = s.substr(8, 2);
int yearI = stoi(year);
int monthI = stoi(month);
int dayI = stoi(day);
if (yearI > 2019) {
cout << "TBD";
} else {
if (monthI > 4) {
cout << "TBD";
} else {
if (dayI > 30) {
cout << "TBD";
} else {
cout << "Heisei";
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string year = s.substr(0, 4);
string month = s.substr(5, 2);
string day = s.substr(8, 2);
int yearI = stoi(year);
int monthI = stoi(month);
int dayI = stoi(day);
if (yearI > 2019) {
cout << "TBD";
} else {
if (monthI > 4) {
cout << "TBD";
} else {
if (dayI > 30) {
cout << "TBD";
} else {
cout << "Heisei";
}
}
}
} | insert | 5 | 5 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 5) > this->size() (which is 0)
|
p03109 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a, b, c, d;
a = (int)(s.at(6) - '0');
b = (int)(s.at(7) - '0');
c = (int)(s.at(9) - '0');
d = (int)(s.at(10) - '0');
if (10 * a + b >= 5) {
cout << "TBD";
} else {
cout << "Heisei";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a, b, c, d;
a = (int)(s.at(5) - '0');
b = (int)(s.at(6) - '0');
c = (int)(s.at(8) - '0');
d = (int)(s.at(9) - '0');
if (10 * a + b >= 5) {
cout << "TBD";
} else {
cout << "Heisei";
}
} | replace | 6 | 10 | 6 | 10 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 10) >= this->size() (which is 10)
|
p03109 | Python | Runtime Error | a = int(input().split("/"))
if a[1] <= 4:
print("Heisei")
else:
print("TBD")
| S = input().split("/")
if int(S[1]) < 5:
print("Heisei")
else:
print("TBD")
| replace | 0 | 2 | 0 | 2 | TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03109/Python/s386069214.py", line 1, in <module>
a = int(input().split("/"))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
|
p03109 | Python | Runtime Error | s = sorted(input())
t = sorted(input())[::-1]
print("Yes" if s < t else "No")
| S = input()
print("Heisei" if S <= "2019/04/30" else "TBD")
| replace | 0 | 3 | 0 | 2 | EOFError: EOF when reading a line | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03109/Python/s553178748.py", line 2, in <module>
t = sorted(input())[:: -1]
EOFError: EOF when reading a line
|
p03109 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld double
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vll vector<ll>
#define pll pair<ll, ll>
#define pld pair<ll, ld>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define ln cout << "\n";
#define test \
ll T; \
cin >> T; \
while (T--)
#define fastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cout << '{';
__print(x.first);
cout << ',';
__print(x.second);
cout << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cout << '{';
for (auto &i : x)
cout << (f++ ? "," : ""), __print(i);
cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cout << ", ";
_print(v...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
ll MIN(ll a = 2e18, ll b = 2e18, ll c = 2e18, ll d = 2e18, ll e = 2e18) {
return min(a, min(b, min(c, min(d, e))));
}
ll MAX(ll a = -2e18, ll b = -2e18, ll c = -2e18, ll d = -2e18, ll e = -2e18) {
return max(a, max(b, max(c, max(d, e))));
}
vll prime; // if i==prime[i] then prime otherwise smallest prime factor of that
// number
void seive(ll n) {
prime.resize(n + 1);
rep(i, 2, n, 1) if (prime[i] == 0) {
prime[i] = i;
rep(j, i * i, n, i) if (prime[j] == 0) prime[j] = i;
}
}
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
int main() {
fastIO
#ifndef ONLINE_JUDGE
#define debug(x...) \
cout << "[" << #x << "] = ["; \
_print(x)
freopen("input.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("out.txt", "w", stderr);
#else
#define debug(x...)
#endif
string s;
cin >> s;
ll m = int(10 * (s[5] - '0') + s[6]) - '0';
ll d = int(s[8] + s[9]);
// cout<<m;
if (m <= 4)
cout << "Heisei";
else
cout << "TBD";
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld double
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vll vector<ll>
#define pll pair<ll, ll>
#define pld pair<ll, ld>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define ln cout << "\n";
#define test \
ll T; \
cin >> T; \
while (T--)
#define fastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cout << '{';
__print(x.first);
cout << ',';
__print(x.second);
cout << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cout << '{';
for (auto &i : x)
cout << (f++ ? "," : ""), __print(i);
cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cout << ", ";
_print(v...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
ll MIN(ll a = 2e18, ll b = 2e18, ll c = 2e18, ll d = 2e18, ll e = 2e18) {
return min(a, min(b, min(c, min(d, e))));
}
ll MAX(ll a = -2e18, ll b = -2e18, ll c = -2e18, ll d = -2e18, ll e = -2e18) {
return max(a, max(b, max(c, max(d, e))));
}
vll prime; // if i==prime[i] then prime otherwise smallest prime factor of that
// number
void seive(ll n) {
prime.resize(n + 1);
rep(i, 2, n, 1) if (prime[i] == 0) {
prime[i] = i;
rep(j, i * i, n, i) if (prime[j] == 0) prime[j] = i;
}
}
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
int main() {
fastIO
string s;
cin >> s;
ll m = int(10 * (s[5] - '0') + s[6]) - '0';
ll d = int(s[8] + s[9]);
// cout<<m;
if (m <= 4)
cout << "Heisei";
else
cout << "TBD";
return 0;
} | replace | 133 | 145 | 133 | 134 | 0 | |
p03109 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int y = stoi(s.substr(0, 4));
int m = stoi(s.substr(4, 2));
int d = stoi(s.substr(7, 2));
if (y > 2019 || (y == 2019 && m > 4))
cout << "TBD";
else
cout << "Heisei";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int y = stoi(s.substr(0, 4));
int m = stoi(s.substr(5, 2));
int d = stoi(s.substr(8, 2));
if (y > 2019 || (y == 2019 && m > 4))
cout << "TBD";
else
cout << "Heisei";
} | replace | 7 | 9 | 7 | 9 | -6 | terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi
|
p03109 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define INT(a) scanf("%d", &a)
#define STR(a) scanf("%s", a)
#define DBL(a) scanf("%lf", &a)
#define LNG(a) scanf("%lld", &a)
#define PI acos(-1)
int main() {
string s;
cin >> s;
int date = 0, year = 0;
bool f = 0;
for (int i = s.length() - 1; i >= 0; i++) {
if (s[i] == '/') {
if (f)
break;
f = 1;
}
if (!f)
date = date * 10 + (s[i] - '0');
else
year = year * 10 + (s[i] - '0');
}
if (year > 4)
cout << "TBD\n";
else
cout << "Heisei\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define INT(a) scanf("%d", &a)
#define STR(a) scanf("%s", a)
#define DBL(a) scanf("%lf", &a)
#define LNG(a) scanf("%lld", &a)
#define PI acos(-1)
int main() {
string s;
cin >> s;
int year = (s[5] - '0') * 10 + (s[6] - '0');
if (year > 4)
cout << "TBD\n";
else
cout << "Heisei\n";
return 0;
} | replace | 11 | 24 | 11 | 13 | 0 | |
p03109 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
scanf("%d/%d/%d", a, b, c);
if (b > 4)
cout << "TBD" << endl;
else
cout << "Heisei" << endl;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
scanf("%d/%d/%d", &a, &b, &c);
if (b > 4)
cout << "TBD" << endl;
else
cout << "Heisei" << endl;
} | replace | 5 | 6 | 5 | 6 | -11 | |
p03109 | C++ | Runtime Error | #include <iostream>
#include <string>
int main() {
std::string S;
std::cin >> S;
std::string s1;
std::string s2;
std::string s3;
s1 = S[0] + S[1] + S[2] + S[3];
s2 = S[5] + S[6];
s3 = S[8] + S[9];
if (std::stoi(s1) <= 2019 && std::stoi(s2) <= 4 && std::stoi(s3) <= 30) {
std::cout << "Heisei" << std::endl;
} else {
std::cout << "TBD" << std::endl;
}
return 0;
} | #include <iostream>
#include <string>
int main() {
std::string S;
std::cin >> S;
std::string s1;
std::string s2;
std::string s3;
s1 = S.substr(0, 4);
s2 = S.substr(5, 2);
s3 = S.substr(8, 2);
if (std::stoi(s1) <= 2019 && std::stoi(s2) <= 4 && std::stoi(s3) <= 30) {
std::cout << "Heisei" << std::endl;
} else {
std::cout << "TBD" << std::endl;
}
return 0;
} | replace | 12 | 15 | 12 | 15 | -6 | terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi
|
p03109 | C++ | Runtime Error | #pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(), (V).end()
#define SORT(V) sort(ALL(V)) // 小さい方からソート
#define REV(V) reverse(ALL(V)) // リバース
#define RSORT(V) \
SORT(V); \
REV(V) // 大きい方からソート
#define NPN(V) next_permutation(ALL(V)) // 順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define RAPID \
cin.tie(0); \
ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define VIN(V) \
for (int i = 0; i < (V).size(); i++) { \
cin >> (V).at(i); \
}
#define OUT(n) cout << n << endl
#define VOUT(V) \
REP(i, (V).size()) { cout << (V)[i] << endl; }
#define VOUT2(V) \
REP(i, (V).size()) { cout << (V)[i] << " "; } \
cout << endl;
// 型マクロ定義
#define int long long
#define P pair<ll, ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll, ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue < ll, V, greater<ll>
//
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最小公倍数
string dlStr(string s, char de) {
string result = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] != de)
result.pb(de);
}
return result;
}
// デフォルト変数定義
int n, m, a, b, c, x, y, z;
double d, e, f;
string s, t;
//
signed main() {
RAPID;
IN(s);
if (stoi(dlStr(s, '/')) <= 20190430)
OUT("Heisei");
else
OUT("TBD");
} | #pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(), (V).end()
#define SORT(V) sort(ALL(V)) // 小さい方からソート
#define REV(V) reverse(ALL(V)) // リバース
#define RSORT(V) \
SORT(V); \
REV(V) // 大きい方からソート
#define NPN(V) next_permutation(ALL(V)) // 順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define RAPID \
cin.tie(0); \
ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define VIN(V) \
for (int i = 0; i < (V).size(); i++) { \
cin >> (V).at(i); \
}
#define OUT(n) cout << n << endl
#define VOUT(V) \
REP(i, (V).size()) { cout << (V)[i] << endl; }
#define VOUT2(V) \
REP(i, (V).size()) { cout << (V)[i] << " "; } \
cout << endl;
// 型マクロ定義
#define int long long
#define P pair<ll, ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll, ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue < ll, V, greater<ll>
//
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最小公倍数
string dlStr(string s, char de) {
string result = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] != de)
result.pb(de);
}
return result;
}
// デフォルト変数定義
int n, m, a, b, c, x, y, z;
double d, e, f;
string s, t;
//
signed main() {
RAPID;
IN(s);
if (s <= "2019/04/30")
OUT("Heisei");
else
OUT("TBD");
} | replace | 77 | 78 | 77 | 78 | -6 | terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi
|
p03109 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string t = "TBD";
string u;
int i;
for (i = 0; i < 10; i++) {
if (s.at(i) != '/') {
u.at(i) = s.at(i);
}
}
int a = stoi(u);
if (a / 10000 < 2019) {
t = "Heisei";
}
if (a / 10000 == 2019 && a - 20190000 <= 430) {
t = "Heisei";
}
cout << t;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string t = "TBD";
if (s <= "2019/04/30") {
t = "Heisei";
}
cout << t;
}
| replace | 6 | 18 | 6 | 7 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p03109 | C++ | Runtime Error | #include <cstdio>
#include <stdio.h>
#include <string.h>
#include <time.h>
int main() {
int y, m, d;
scanf("%d/%d/%d", y, m, d);
if (y > 2019 || y == 2019 && m >= 5) {
printf("TBD");
} else {
printf("Heisei");
}
return 0;
} | #include <cstdio>
#include <stdio.h>
#include <string.h>
#include <time.h>
int main() {
int y, m, d;
scanf("%d/%d/%d", &y, &m, &d);
if (y > 2019 || y == 2019 && m >= 5) {
printf("TBD");
} else {
printf("Heisei");
}
return 0;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p03109 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9 + 7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL) - 9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(9);
string S;
cin >> S;
if (stoi("" + S[5] + S[6]) > 4)
cout << "TBD" << endl;
else
cout << "Heisei" << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9 + 7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL) - 9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(9);
string S;
cin >> S;
if (S[5] == '1' || S[6] > '4')
cout << "TBD" << endl;
else
cout << "Heisei" << endl;
return 0;
} | replace | 39 | 40 | 39 | 40 | -6 | terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi
|
p03110 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_N = 1;
int main() {
double ans = 0;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string s;
double x;
cin >> x >> s;
if (s[0] == 'B')
x *= 380000.0;
ans += x;
}
printf("%llf\n", ans);
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_N = 1;
int main() {
double ans = 0;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string s;
double x;
cin >> x >> s;
if (s[0] == 'B')
x *= 380000.0;
ans += x;
}
cout << ans << endl;
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p03110 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i > 0; i++)
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
cout << fixed << setprecision(10);
double ans = 0;
rep(i, n) {
double mass = 0;
string coin = 0;
cin >> mass >> coin;
if (coin == "JPY")
ans += mass;
if (coin == "BTC")
ans += mass * 380000.0;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i > 0; i++)
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
cout << fixed << setprecision(10);
double ans = 0;
rep(i, n) {
double mass;
string coin;
cin >> mass >> coin;
if (coin == "JPY")
ans += mass;
if (coin == "BTC")
ans += mass * 380000.0;
}
cout << ans << endl;
}
| replace | 15 | 17 | 15 | 17 | -6 | terminate called after throwing an instance of 'std::logic_error'
what(): basic_string: construction from null is not valid
|
p03110 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n, i;
double s;
s = 0;
cin >> n;
double a[n];
string u[n];
for (i = 1; i <= n; i++) {
cin >> a[i] >> u[i];
if (u[i] == "JPY") {
s = s + a[i];
} else if (u[i] == "BTC") {
s = s + a[i] * 380000;
}
}
cout << s << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int n, i;
double s;
s = 0;
cin >> n;
double a[n];
string u[n];
for (i = 0; i <= n - 1; i++) {
cin >> a[i] >> u[i];
if (u[i] == "JPY") {
s = s + a[i];
} else if (u[i] == "BTC") {
s = s + a[i] * 380000;
}
}
cout << s << endl;
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03110 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double x[n], s = 0;
string t[n];
for (int i = 0; i < n; i++) {
cin >> x[i] >> t[i];
if (t[n] == "JPY")
s += x[i];
else
s += x[i] * 380000;
}
cout << fixed << setprecision(15) << s;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double x[n], s = 0;
string t[n];
for (int i = 0; i < n; i++) {
cin >> x[i] >> t[i];
if (t[i] == "JPY")
s += x[i];
else
s += x[i] * 380000;
}
cout << fixed << setprecision(15) << s;
}
| replace | 9 | 10 | 9 | 10 | -11 | |
p03110 | Python | Runtime Error | N = int(input())
sum = 0.0
for i in range(N):
x = float(input())
u = input()
if u == "JPY":
sum = sum + x
else:
sum = sum + x * 380000
print(sum)
| N = int(input())
sum = 0.0
for i in range(N):
S = input()
S = S.split()
x = float(S[0])
u = S[1]
if u == "JPY":
sum = sum + x
else:
sum = sum + x * 380000
print(sum)
| replace | 5 | 7 | 5 | 10 | ValueError: could not convert string to float: '10000 JPY' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03110/Python/s819401905.py", line 6, in <module>
x = float(input())
ValueError: could not convert string to float: '10000 JPY'
|
p03110 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define all(collection) (collection).begin(), (collection).end()
#define loop(i, times) for (int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) \
for (int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) \
for (int i = start_index; i <= end_index; i++)
int mp = 0;
int main() {
int n;
cin >> n;
vector<pair<string, string>> s(n);
double sum = 0;
for (const auto &e : s) {
if (get<1>(e) == "JPY") {
sum += stod(get<0>(e));
} else {
sum += (stod(get<0>(e)) * 380000.0);
}
}
cout << sum;
return 0;
} | #include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define all(collection) (collection).begin(), (collection).end()
#define loop(i, times) for (int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) \
for (int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) \
for (int i = start_index; i <= end_index; i++)
int mp = 0;
int main() {
int n;
cin >> n;
vector<pair<string, string>> s(n);
loop(i, n) {
cin >> get<0>(s[i]);
cin >> get<1>(s[i]);
}
double sum = 0;
for (const auto &e : s) {
if (get<1>(e) == "JPY") {
sum += stod(get<0>(e));
} else {
sum += (stod(get<0>(e)) * 380000.0);
}
}
cout << sum;
return 0;
} | insert | 25 | 25 | 25 | 30 | -6 | terminate called after throwing an instance of 'std::invalid_argument'
what(): stod
|
p03111 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long int LL;
typedef vector<LL> VL;
typedef unsigned long long int ULL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define LET(x, a) __typeof(a) x(a)
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// Works for forward as well as backward iteration
#define gu getchar
#define pu putchar
#define si(n) cin >> n
#define dout(n) cout << n << "\n"
// # define M_PI 3.14159265358979323846264338327950288
#define DRT() \
int t; \
si(t); \
while (t--)
#define PlUSWRAP(index, n) \
index = (index + 1) % n // index++; if(index>=n) index=0
#define MINUSWRAP(index, n) \
index = (index + n - 1) % n // index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) \
d = (int)((double)d + 0.5) // Round off d to nearest integer
#define FLUSHN while (gu() != '\n')
#define FLUSHS while (gu() != ' ')
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define off \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
// set_name.find_by_order(k) It returns to an iterator to the kth element
// (counting from zero) in the set in O(logn) time set_name.order_of_key(k) It
// returns to the number of items that are strictly smaller than our item k in
// O(logn) time.
LL n, A, B, C;
VL arr;
LL rec(LL cur, LL a, LL b, LL c) {
if (cur == n) {
if (min(a, min(b, c)) > 0) {
// we subtract 30 because including some number for the first time does
// not cost 10 MP(Magic Points), this cost is only for combination
return abs(a - A) + abs(b - B) + abs(c - C) - 30;
} else
return INT_MAX;
}
LL r1 = rec(cur + 1, a, b, c);
LL r2 = rec(cur + 1, a + arr[cur], b, c) + 10;
LL r3 = rec(cur + 1, a, b + arr[cur], c) + 10;
LL r4 = rec(cur + 1, a, b, c + arr[cur]) + 10;
return min(min(r1, r2), min(r3, r4));
}
int main() {
#ifndef ONLINE_JUDGE
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#endif
srand(chrono::steady_clock::now().time_since_epoch().count());
off;
cin >> n >> A >> B >> C;
cout << rec(0, 0, 0, 0);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long int LL;
typedef vector<LL> VL;
typedef unsigned long long int ULL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define LET(x, a) __typeof(a) x(a)
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// Works for forward as well as backward iteration
#define gu getchar
#define pu putchar
#define si(n) cin >> n
#define dout(n) cout << n << "\n"
// # define M_PI 3.14159265358979323846264338327950288
#define DRT() \
int t; \
si(t); \
while (t--)
#define PlUSWRAP(index, n) \
index = (index + 1) % n // index++; if(index>=n) index=0
#define MINUSWRAP(index, n) \
index = (index + n - 1) % n // index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) \
d = (int)((double)d + 0.5) // Round off d to nearest integer
#define FLUSHN while (gu() != '\n')
#define FLUSHS while (gu() != ' ')
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define off \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
// set_name.find_by_order(k) It returns to an iterator to the kth element
// (counting from zero) in the set in O(logn) time set_name.order_of_key(k) It
// returns to the number of items that are strictly smaller than our item k in
// O(logn) time.
LL n, A, B, C;
VL arr;
LL rec(LL cur, LL a, LL b, LL c) {
if (cur == n) {
if (min(a, min(b, c)) > 0) {
// we subtract 30 because including some number for the first time does
// not cost 10 MP(Magic Points), this cost is only for combination
return abs(a - A) + abs(b - B) + abs(c - C) - 30;
} else
return INT_MAX;
}
LL r1 = rec(cur + 1, a, b, c);
LL r2 = rec(cur + 1, a + arr[cur], b, c) + 10;
LL r3 = rec(cur + 1, a, b + arr[cur], c) + 10;
LL r4 = rec(cur + 1, a, b, c + arr[cur]) + 10;
return min(min(r1, r2), min(r3, r4));
}
int main() {
#ifndef ONLINE_JUDGE
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#endif
srand(chrono::steady_clock::now().time_since_epoch().count());
off;
cin >> n >> A >> B >> C;
arr.resize(n);
rep(i, 0, n) { cin >> arr[i]; }
cout << rec(0, 0, 0, 0);
return 0;
} | insert | 96 | 96 | 96 | 98 | 0 | |
p03111 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(n, m, v) vector<long long> v((n), (m));
int ans = INT_MAX;
int n;
vec(8, 0, k);
int a[3];
vec(8, 0, v);
void init() {
cin >> n >> a[0] >> a[1] >> a[2];
rep(i, n) cin >> v[i];
}
int dfs(int i) {
if (i == n) {
int mp = 0;
vec(4, 0, cnt);
vec(3, 0, tmp);
/* rep(kk,n){
cout<<k[kk]<<" ";
}
cout<<endl;*/
rep(jj, n) {
cnt[k[jj]]++;
tmp[k[jj]] += v[jj];
}
if (cnt[0] * cnt[1] * cnt[2] != 0) {
rep(jj, 3) mp += abs(tmp[jj] - a[jj]);
mp += ((cnt[0] + cnt[1] + cnt[2] - 3) * 10);
return mp;
}
return INT_MAX;
}
rep(j, 4) {
k[i] = j;
// cout<<"dd"<<endl;
ans = min(dfs(i + 1), ans);
}
return ans;
}
int main() {
init();
cout << dfs(0) << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(n, m, v) vector<int> v((n), (m));
int ans = INT_MAX;
int n;
vec(8, 0, k);
int a[3];
vec(8, 0, v);
void init() {
cin >> n >> a[0] >> a[1] >> a[2];
rep(i, n) cin >> v[i];
}
int dfs(int i) {
if (i == n) {
int mp = 0;
vec(4, 0, cnt);
vec(3, 0, tmp);
/* rep(kk,n){
cout<<k[kk]<<" ";
}
cout<<endl;*/
rep(jj, n) {
cnt[k[jj]]++;
tmp[k[jj]] += v[jj];
}
if (cnt[0] * cnt[1] * cnt[2] != 0) {
rep(jj, 3) mp += abs(tmp[jj] - a[jj]);
mp += ((cnt[0] + cnt[1] + cnt[2] - 3) * 10);
return mp;
}
return INT_MAX;
}
rep(j, 4) {
k[i] = j;
// cout<<"dd"<<endl;
ans = min(dfs(i + 1), ans);
}
return ans;
}
int main() {
init();
cout << dfs(0) << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p03111 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
ll N, A, B, C;
std::vector<long long> l(N + 1);
bool graph[nmax][nmax];
ll ans = LONG_MAX;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
ll mulMod(ll a, ll b) { return (((a % MOD) * (b % MOD)) % MOD); }
ll calc(vector<ll> v) {
ll cost = 0;
ll a = 0, b = 0, c = 0;
for (auto &&i : v) {
switch (i) {
case 1:
if (a != 0)
cost += 10;
a += i;
break;
case 2:
if (b != 0)
cost += 10;
b += i;
break;
case 3:
if (c != 0)
cost += 10;
c += i;
break;
default:
break;
}
}
cost += abs(A - a);
cost += abs(B - b);
cost += abs(C - c);
return cost;
}
int dfs(int n, int na, int a, int nb, int b, int nc, int c) {
if (n == N) {
if (na == 0 || nb == 0 || nc == 0)
return 1000000000;
return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (na + nb + nc - 3);
}
int tmp1, tmp2, tmp3, tmp4;
tmp1 = dfs(n + 1, na + 1, a + l[n], nb, b, nc, c);
tmp2 = dfs(n + 1, na, a, nb + 1, b + l[n], nc, c);
tmp3 = dfs(n + 1, na, a, nb, b, nc + 1, c + l[n]);
tmp4 = dfs(n + 1, na, a, nb, b, nc, c);
int ans;
ans = min(min(min(tmp1, tmp2), tmp3), tmp4);
return ans;
}
int main() {
scanf("%lld", &N);
scanf("%lld", &A);
scanf("%lld", &B);
scanf("%lld", &C);
for (int i = 0; i < N; i++) {
scanf("%lld", &l[i]);
}
cout << dfs(0, 0, 0, 0, 0, 0, 0) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
ll N, A, B, C;
std::vector<long long> l(N + 100);
bool graph[nmax][nmax];
ll ans = LONG_MAX;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
ll mulMod(ll a, ll b) { return (((a % MOD) * (b % MOD)) % MOD); }
ll calc(vector<ll> v) {
ll cost = 0;
ll a = 0, b = 0, c = 0;
for (auto &&i : v) {
switch (i) {
case 1:
if (a != 0)
cost += 10;
a += i;
break;
case 2:
if (b != 0)
cost += 10;
b += i;
break;
case 3:
if (c != 0)
cost += 10;
c += i;
break;
default:
break;
}
}
cost += abs(A - a);
cost += abs(B - b);
cost += abs(C - c);
return cost;
}
int dfs(int n, int na, int a, int nb, int b, int nc, int c) {
if (n == N) {
if (na == 0 || nb == 0 || nc == 0)
return 1000000000;
return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (na + nb + nc - 3);
}
int tmp1, tmp2, tmp3, tmp4;
tmp1 = dfs(n + 1, na + 1, a + l[n], nb, b, nc, c);
tmp2 = dfs(n + 1, na, a, nb + 1, b + l[n], nc, c);
tmp3 = dfs(n + 1, na, a, nb, b, nc + 1, c + l[n]);
tmp4 = dfs(n + 1, na, a, nb, b, nc, c);
int ans;
ans = min(min(min(tmp1, tmp2), tmp3), tmp4);
return ans;
}
int main() {
scanf("%lld", &N);
scanf("%lld", &A);
scanf("%lld", &B);
scanf("%lld", &C);
for (int i = 0; i < N; i++) {
scanf("%lld", &l[i]);
}
cout << dfs(0, 0, 0, 0, 0, 0, 0) << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03111 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
typedef pair<ll, ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double, ll> &firstElof,
const pair<double, ll> &secondElof) {
return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double, ll> &firstElof,
const pair<double, ll> &secondElof) {
return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N] = {0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll fib(ll a) {
if (fibl[a] != 0)
return fibl[a];
if (a == 0) {
return 0;
} else if (a == 1) {
return 1;
}
return fibl[a] = fib(a - 1) + fib(a - 2);
}
ll eratosthenes(ll n) {
int p = 0;
for (ll i = 0; i <= n; ++i)
x[i] = true;
x[0] = x[1] = false;
for (int i = 2; i <= n; ++i) {
if (x[i]) {
p++;
for (int j = 2 * i; j <= n; j += i)
x[j] = false;
}
num[i] = p;
}
return p;
}
ll gcd(ll a, ll b) {
if (a % b == 0)
return (b);
else
return (gcd(b, a % b));
}
ll keta(ll N) {
int tmp{};
while (N > 0) {
tmp += (N % 10);
N /= 10;
}
N = tmp;
return N;
}
void base_num(ll data, ll base) {
if (data == 0)
return;
ll next = abs(data) % abs(base);
if (data < 0)
next = (abs(base) - next) % abs(base);
base_num((data - next) / base, base);
cout << next;
}
ll nx[9], n, A, B, C;
ll dfs(ll co, ll a, ll b, ll c) {
ll r0, r1, r2, r3;
if (co == n) {
ll x = 30;
if (min(min(a, b), c) > 0) {
return abs(a - A) + abs(b - B) + abs(c - C) - x;
}
}
r0 = dfs(co + 1, a, b, c);
r1 = dfs(co + 1, a + nx[co], b, c) + 10;
r2 = dfs(co + 1, a, b + nx[co], c) + 10;
r3 = dfs(co + 1, a, b, c + nx[co]) + 10;
return min(min(r0, r1), min(r2, r3));
}
int main() {
cin >> n >> A >> B >> C;
for (ll i = 0; i < n; i++) {
cin >> nx[i];
}
cout << dfs(0, 0, 0, 0) << endl;
}
| #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
typedef pair<ll, ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double, ll> &firstElof,
const pair<double, ll> &secondElof) {
return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double, ll> &firstElof,
const pair<double, ll> &secondElof) {
return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N] = {0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll fib(ll a) {
if (fibl[a] != 0)
return fibl[a];
if (a == 0) {
return 0;
} else if (a == 1) {
return 1;
}
return fibl[a] = fib(a - 1) + fib(a - 2);
}
ll eratosthenes(ll n) {
int p = 0;
for (ll i = 0; i <= n; ++i)
x[i] = true;
x[0] = x[1] = false;
for (int i = 2; i <= n; ++i) {
if (x[i]) {
p++;
for (int j = 2 * i; j <= n; j += i)
x[j] = false;
}
num[i] = p;
}
return p;
}
ll gcd(ll a, ll b) {
if (a % b == 0)
return (b);
else
return (gcd(b, a % b));
}
ll keta(ll N) {
int tmp{};
while (N > 0) {
tmp += (N % 10);
N /= 10;
}
N = tmp;
return N;
}
void base_num(ll data, ll base) {
if (data == 0)
return;
ll next = abs(data) % abs(base);
if (data < 0)
next = (abs(base) - next) % abs(base);
base_num((data - next) / base, base);
cout << next;
}
ll nx[9], n, A, B, C;
ll dfs(ll co, ll a, ll b, ll c) {
ll r0, r1, r2, r3;
if (co == n) {
ll x = 30;
if (min(min(a, b), c) > 0) {
return abs(a - A) + abs(b - B) + abs(c - C) - x;
} else {
return INF;
}
}
r0 = dfs(co + 1, a, b, c);
r1 = dfs(co + 1, a + nx[co], b, c) + 10;
r2 = dfs(co + 1, a, b + nx[co], c) + 10;
r3 = dfs(co + 1, a, b, c + nx[co]) + 10;
return min(min(r0, r1), min(r2, r3));
}
int main() {
cin >> n >> A >> B >> C;
for (ll i = 0; i < n; i++) {
cin >> nx[i];
}
cout << dfs(0, 0, 0, 0) << endl;
}
| insert | 113 | 113 | 113 | 115 | -11 | |
p03111 | C++ | Runtime Error | #include <iostream>
#include <string>
#include <vector>
const int INF = 1000000000;
int n;
int target[3];
std::vector<int> l;
// ref : https://img.atcoder.jp/abc119/editorial.pdf
// ref : https://drken1215.hatenablog.com/entry/2019/02/24/224100
/*
延長、縮小は合成の前後どっちでやろうが同じ
->
合成魔法を一切これ以降使用しない場合に限り延長、縮小魔法を使用としても一般性は失われない
目的を達成するに当たって竹はA, B, Cの材料or一切使わないの4通り
-> N本あるので4^N通り
そこで合成するペアだけ全探索すればあとは目標の長さを得るためのコストを計算すればok
*/
int solve(int i = 0, int a = 0, int b = 0, int c = 0) {
if (i == n) {
// どれも目標の長さを作るのに使っていない場合はダメ
if (!a || !b || !c)
return INF;
else
return std::abs(a - target[0]) + std::abs(b - target[1]) +
std::abs(c - target[2]);
}
int cost = INF;
cost = std::min(cost, solve(i + 1, a, b, c)); // この竹を使わない
// 以降使う, このとき最初の1本目は合成できていないので+10しないことに注意
cost = std::min(cost, solve(i + 1, a + l[i], b, c) + (a ? 10 : 0));
cost = std::min(cost, solve(i + 1, a, b + l[i], c) + (b ? 10 : 0));
cost = std::min(cost, solve(i + 1, a, b, c + l[i]) + (c ? 10 : 0));
return cost;
}
int main() {
std::cin >> n;
l.assign(3, 0);
for (int i = 0; i < 3; i++)
std::cin >> target[i];
for (int i = 0; i < n; i++) {
std::cin >> l[i];
}
std::cout << solve() << std::endl;
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
const int INF = 1000000000;
int n;
int target[3];
std::vector<int> l;
// ref : https://img.atcoder.jp/abc119/editorial.pdf
// ref : https://drken1215.hatenablog.com/entry/2019/02/24/224100
/*
延長、縮小は合成の前後どっちでやろうが同じ
->
合成魔法を一切これ以降使用しない場合に限り延長、縮小魔法を使用としても一般性は失われない
目的を達成するに当たって竹はA, B, Cの材料or一切使わないの4通り
-> N本あるので4^N通り
そこで合成するペアだけ全探索すればあとは目標の長さを得るためのコストを計算すればok
*/
int solve(int i = 0, int a = 0, int b = 0, int c = 0) {
if (i == n) {
// どれも目標の長さを作るのに使っていない場合はダメ
if (!a || !b || !c)
return INF;
else
return std::abs(a - target[0]) + std::abs(b - target[1]) +
std::abs(c - target[2]);
}
int cost = INF;
cost = std::min(cost, solve(i + 1, a, b, c)); // この竹を使わない
// 以降使う, このとき最初の1本目は合成できていないので+10しないことに注意
cost = std::min(cost, solve(i + 1, a + l[i], b, c) + (a ? 10 : 0));
cost = std::min(cost, solve(i + 1, a, b + l[i], c) + (b ? 10 : 0));
cost = std::min(cost, solve(i + 1, a, b, c + l[i]) + (c ? 10 : 0));
return cost;
}
int main() {
std::cin >> n;
l.assign(n, 0);
for (int i = 0; i < 3; i++)
std::cin >> target[i];
for (int i = 0; i < n; i++) {
std::cin >> l[i];
}
std::cout << solve() << std::endl;
return 0;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p03111 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
// typedef pair<string,string> P;
// double dat[100][100];
// int dp[6][1010];//動的計画法
// int prime[100001];
// char str[1010][1010];
// vector<pair<ll,ll>> pc;
// int ABS(int a){return max(a,-a);}
// int a[100001];
const int INF = 100000009;
int N, A, B, C;
vector<int> l;
int dfs(int cur, int a, int b, int c) {
if (cur == N) {
if (min(a, min(b, c)) > 0)
return abs(a - A) + abs(b - B) + abs(c - C) - 30;
else
return INF;
}
int ret0 = dfs(cur + 1, a, b, c);
int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
return min(min(ret0, ret1), min(ret2, ret3));
}
int main() {
cin >> N >> A >> B >> C;
for (int i = 0; i > N; i++) {
int a;
cin >> a;
l.push_back(a);
}
cout << dfs(0, 0, 0, 0) << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
// typedef pair<string,string> P;
// double dat[100][100];
// int dp[6][1010];//動的計画法
// int prime[100001];
// char str[1010][1010];
// vector<pair<ll,ll>> pc;
// int ABS(int a){return max(a,-a);}
// int a[100001];
const int INF = 100000009;
int N, A, B, C;
vector<int> l;
int dfs(int cur, int a, int b, int c) {
if (cur == N) {
if (min(a, min(b, c)) > 0)
return abs(a - A) + abs(b - B) + abs(c - C) - 30;
else
return INF;
}
int ret0 = dfs(cur + 1, a, b, c);
int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
return min(min(ret0, ret1), min(ret2, ret3));
}
int main() {
cin >> N >> A >> B >> C;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
l.push_back(a);
}
cout << dfs(0, 0, 0, 0) << endl;
return 0;
} | replace | 42 | 43 | 42 | 43 | -11 | |
p03111 | C++ | Runtime Error | /*
∧_∧ やあ
(´・ω・`) / ようこそ、バーボンハウスへ。
/∇y:::::\
[ ̄] このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
|:⊃:|:::::| |──|
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| うん、「また」なんだ。済まない。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| ̄
仏の顔もって言うしね、謝って許してもらおうとも思っていない。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄/|
∇ ∇ ∇ ∇ /./| でも、この提出を見たとき、君は、きっと言葉では言い表せない
┴ ┴ ┴ ┴ / /
| 「ときめき」みたいなものを感じてくれたと思う。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|/
| 殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ | そう思って、この提出を投げたんだ。
(⊆⊇) (⊆⊇) (⊆⊇) |
|| || || | じゃあ、判定を聞こうか。
./|\ /|\ /|\
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) \
cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) \
cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y \
<< ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
lint c, b, a, num;
vector<lint> l(n);
cin >> c >> b >> a;
for (int i = 0; i < n; ++i) {
cin >> l[i];
}
lint loop = 1;
lint pow[9];
for (int i = 0; i <= n; ++i) {
pow[i] = loop;
loop *= 4;
// debug(pow[i]);
}
lint use[8];
lint len[3];
lint count[3];
lint ans = INF;
for (int i = 0; i < pow[n]; ++i) {
num = i;
for (int j = 0; j < 3; ++j) {
len[j] = 0;
count[j] = 0;
}
for (int j = 7; j >= 0; --j) {
use[j] = num / pow[j];
num -= (num / pow[j]) * pow[j];
// debug(use[j]);
}
lint mp = 0;
for (int j = 0; j < n; ++j) {
if (use[j] == 0) {
// use for A
count[0]++;
len[0] += l[j];
} else if (use[j] == 1) {
// use for B
count[1]++;
len[1] += l[j];
} else if (use[j] == 2) {
count[2]++;
len[2] += l[j];
}
}
if (count[0] == 0 || count[1] == 0 || count[2] == 0) {
continue;
} else {
if (count[0] == 1) {
mp += abs(len[0] - a);
} else {
mp += abs(len[0] - a) + 10 * (count[0] - 1);
}
if (count[1] == 1) {
mp += abs(len[1] - b);
} else {
mp += abs(len[1] - b) + 10 * (count[1] - 1);
}
if (count[2] == 1) {
mp += abs(len[2] - c);
} else {
mp += abs(len[2] - c) + 10 * (count[2] - 1);
}
// debug(mp);
ans = min(ans, mp);
}
}
cout << ans << endl;
return 0;
} | /*
∧_∧ やあ
(´・ω・`) / ようこそ、バーボンハウスへ。
/∇y:::::\
[ ̄] このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
|:⊃:|:::::| |──|
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| うん、「また」なんだ。済まない。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| ̄
仏の顔もって言うしね、謝って許してもらおうとも思っていない。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄/|
∇ ∇ ∇ ∇ /./| でも、この提出を見たとき、君は、きっと言葉では言い表せない
┴ ┴ ┴ ┴ / /
| 「ときめき」みたいなものを感じてくれたと思う。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|/
| 殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ | そう思って、この提出を投げたんだ。
(⊆⊇) (⊆⊇) (⊆⊇) |
|| || || | じゃあ、判定を聞こうか。
./|\ /|\ /|\
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) \
cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) \
cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y \
<< ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
lint c, b, a, num;
vector<lint> l(n);
cin >> c >> b >> a;
for (int i = 0; i < n; ++i) {
cin >> l[i];
}
lint loop = 1;
lint pow[9];
for (int i = 0; i <= 8; ++i) {
pow[i] = loop;
loop *= 4;
// debug(pow[i]);
}
lint use[8];
lint len[3];
lint count[3];
lint ans = INF;
for (int i = 0; i < pow[n]; ++i) {
num = i;
for (int j = 0; j < 3; ++j) {
len[j] = 0;
count[j] = 0;
}
for (int j = 7; j >= 0; --j) {
use[j] = num / pow[j];
num -= (num / pow[j]) * pow[j];
// debug(use[j]);
}
lint mp = 0;
for (int j = 0; j < n; ++j) {
if (use[j] == 0) {
// use for A
count[0]++;
len[0] += l[j];
} else if (use[j] == 1) {
// use for B
count[1]++;
len[1] += l[j];
} else if (use[j] == 2) {
count[2]++;
len[2] += l[j];
}
}
if (count[0] == 0 || count[1] == 0 || count[2] == 0) {
continue;
} else {
if (count[0] == 1) {
mp += abs(len[0] - a);
} else {
mp += abs(len[0] - a) + 10 * (count[0] - 1);
}
if (count[1] == 1) {
mp += abs(len[1] - b);
} else {
mp += abs(len[1] - b) + 10 * (count[1] - 1);
}
if (count[2] == 1) {
mp += abs(len[2] - c);
} else {
mp += abs(len[2] - c) + 10 * (count[2] - 1);
}
// debug(mp);
ans = min(ans, mp);
}
}
cout << ans << endl;
return 0;
} | replace | 69 | 70 | 69 | 70 | 0 | |
p03111 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N, A, B, C;
int l[8];
int dfs(int cur, int a, int b, int c) {
if (cur == N) {
if (min(a, min(b, c)) > 0) {
return abs(a - A) + abs(b - B) + abs(c - C) - 30;
}
}
int ret0 = dfs(cur + 1, a, b, c);
int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
return min(ret0, min(ret1, min(ret2, ret3)));
}
int main() {
cin >> N >> A >> B >> C;
for (int i = 0; i < N; i++) {
cin >> l[i];
}
cout << dfs(0, 0, 0, 0) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int N, A, B, C;
int l[8];
int dfs(int cur, int a, int b, int c) {
if (cur == N) {
if (min(a, min(b, c)) > 0) {
return abs(a - A) + abs(b - B) + abs(c - C) - 30;
} else {
return 1e9;
}
}
int ret0 = dfs(cur + 1, a, b, c);
int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
return min(ret0, min(ret1, min(ret2, ret3)));
}
int main() {
cin >> N >> A >> B >> C;
for (int i = 0; i < N; i++) {
cin >> l[i];
}
cout << dfs(0, 0, 0, 0) << endl;
}
| insert | 11 | 11 | 11 | 13 | -11 | |
p03111 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, a, b, c, i, l[9], ans;
void dfs(int x, int A, int B, int C, int s) {
if (x > n && A && B && C) {
ans = min(ans, s + abs(a - A) + abs(b - B) + abs(c - C));
return;
}
dfs(x + 1, A, B, C, s);
dfs(x + 1, A + l[x], B, C, s + 10 * (A > 0));
dfs(x + 1, A, B + l[x], C, s + 10 * (B > 0));
dfs(x + 1, A, B, C + l[x], s + 10 * (C > 0));
}
int main() {
ans = 1e9;
cin >> n >> a >> b >> c;
for (i = 1; i <= n; i++)
cin >> l[i];
dfs(1, 0, 0, 0, 0);
printf("%d", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, a, b, c, i, l[9], ans;
void dfs(int x, int A, int B, int C, int s) {
if (x > n) {
if (A && B && C)
ans = min(ans, s + abs(a - A) + abs(b - B) + abs(c - C));
return;
}
dfs(x + 1, A, B, C, s);
dfs(x + 1, A + l[x], B, C, s + 10 * (A > 0));
dfs(x + 1, A, B + l[x], C, s + 10 * (B > 0));
dfs(x + 1, A, B, C + l[x], s + 10 * (C > 0));
}
int main() {
ans = 1e9;
cin >> n >> a >> b >> c;
for (i = 1; i <= n; i++)
cin >> l[i];
dfs(1, 0, 0, 0, 0);
printf("%d", ans);
return 0;
}
| replace | 4 | 6 | 4 | 7 | -11 | |
p03111 | C++ | Runtime Error | #include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
int N, A, B, C, l[8] = {};
long long mpsum, mpmin = 9999999999;
void dfs(int depth, vector<int> v) {
if (depth == N) { // ここから計算部
int num[4] = {}; // 使われた回数を確認
int a = 0, b = 0, c = 0; // a,b,cのmp消費前の竹の長さ
for (int i = 0; i < N; i++) {
num[v[i]] += 1;
if (v[i] == 1)
a += l[i];
if (v[i] == 2)
b += l[i];
if (v[i] == 3)
c += l[i];
}
if (num[1] != 0 && num[2] != 0 && num[3] != 0) {
mpsum = (abs(A - a) + abs(B - b) + abs(C - c) +
(num[1] + num[2] + num[3] - 3) * 10);
if (mpsum < mpmin)
mpmin = mpsum;
}
// ここまで計算部
} else {
for (int i = 0; i < 4; i++) {
v[depth] = i;
dfs(depth + 1, v);
}
}
}
int main() {
cin >> N >> A >> B >> C;
for (int i = 0; i < N; i++)
cin >> l[i];
int depth = 0;
vector<int> v;
dfs(depth, v);
cout << mpmin << endl;
return 0;
} | #include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
int N, A, B, C, l[8] = {};
long long mpsum, mpmin = 9999999999;
void dfs(int depth, vector<int> v) {
if (depth == N) { // ここから計算部
int num[4] = {}; // 使われた回数を確認
int a = 0, b = 0, c = 0; // a,b,cのmp消費前の竹の長さ
for (int i = 0; i < N; i++) {
num[v[i]] += 1;
if (v[i] == 1)
a += l[i];
if (v[i] == 2)
b += l[i];
if (v[i] == 3)
c += l[i];
}
if (num[1] != 0 && num[2] != 0 && num[3] != 0) {
mpsum = (abs(A - a) + abs(B - b) + abs(C - c) +
(num[1] + num[2] + num[3] - 3) * 10);
if (mpsum < mpmin)
mpmin = mpsum;
}
// ここまで計算部
} else {
for (int i = 0; i < 4; i++) {
v[depth] = i;
dfs(depth + 1, v);
}
}
}
int main() {
cin >> N >> A >> B >> C;
for (int i = 0; i < N; i++)
cin >> l[i];
vector<int> v(8, 0);
dfs(0, v);
cout << mpmin << endl;
return 0;
} | replace | 40 | 43 | 40 | 42 | -11 | |
p03111 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define spa << " " <<
#define lfs << fixed << setprecision(10) <<
#define test cout << "test" << endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define rrep(i, n, m) for (ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
void pmod(ll &a, ll b) { a = (a + b) % MOD; }
void pmod(ll &a, ll b, ll c) { a = (b + c) % MOD; }
void qmod(ll &a, ll b) { a = (a * b) % MOD; }
void qmod(ll &a, ll b, ll c) { a = (b * c) % MOD; }
ll median(ll a, ll b, ll c) {
return a + b + c - max({a, b, c}) - min({a, b, c});
}
void ans1(bool x) {
if (x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool x) {
if (x)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void ans3(bool x) {
if (x)
cout << "Yay!" << endl;
else
cout << ":(" << endl;
}
template <typename T1, typename T2> void ans(bool x, T1 y, T2 z) {
if (x)
cout << y << endl;
else
cout << z << endl;
}
template <typename T> void debug(vector<vector<T>> v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
cout << v[i][0];
for (ll j = 1; j < w; j++)
cout spa v[i][j];
cout << endl;
}
};
void debug(vector<string> v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++)
cout << v[i][j];
cout << endl;
}
};
template <typename T> void debug(vector<T> v, ll n) {
if (n != 0)
cout << v[0];
for (ll i = 1; i < n; i++)
cout spa v[i];
cout << endl;
};
template <typename T> vector<vector<T>> vec(ll x, ll y, T w) {
vector<vector<T>> v(x, vector<T>(y, w));
return v;
}
ll gcd(ll x, ll y) {
ll r;
while (y != 0 && (r = x % y) != 0) {
x = y;
y = r;
}
return y == 0 ? x : y;
}
template <typename T> vector<ll> dx = {1, 0, -1, 0, 1, 1, -1, -1};
vector<ll> dy = {0, 1, 0, -1, 1, -1, 1, -1};
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
template <ll base, ll sz> struct Bits {
vector<ll> data;
ll value;
Bits() { data.assign(sz, 0); };
Bits(ll k) {
data.assign(sz, 0);
build(k);
}
void build(ll k) {
for (ll i = 0; i < sz; i++) {
data[i] = k % base;
k /= base;
}
}
Bits &operator=(const ll k) {
fill(ALL(this->data), 0);
this->build(k);
}
ll operator[](const ll k) { return this->data.at(k); }
ll pow(ll k) {
ll ret = 1;
while (k--)
ret *= base;
return ret;
}
void print() {
for (ll i = sz - 1; i >= 0; i--) {
if (i != sz - 1)
cout << " ";
cout << data[i];
}
cout << endl;
}
vector<ll> count(ll k) {
vector<ll> ret(base);
for (ll i = 0; i < k; i++)
ret[data[i]]++;
return ret;
}
};
using bits = Bits<4, 10>;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
ll res = 0, res1 = INF, res2 = -INF, buf = 0;
bool judge = true;
vector<ll> a(3);
ll n;
cin >> n >> a[0] >> a[1] >> a[2];
vector<ll> l(n);
rep(i, 0, n) cin >> l[i];
bits x;
ll k = x.pow(n);
rep(i, 0, k) {
x = i;
auto v = x.count(n);
if (v[0] == 0 || v[1] == 0 || v[2] == 0)
continue;
vector<ll> sumbuf(3);
rep(i, 0, n) { sumbuf[x[i]] += l[i]; }
ll tmp = (n - 3 - v[3]) * 10;
rep(i, 0, 3) tmp += abs(a[i] - sumbuf[i]);
chmin(res1, tmp);
}
cout << res1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define spa << " " <<
#define lfs << fixed << setprecision(10) <<
#define test cout << "test" << endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define rrep(i, n, m) for (ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
void pmod(ll &a, ll b) { a = (a + b) % MOD; }
void pmod(ll &a, ll b, ll c) { a = (b + c) % MOD; }
void qmod(ll &a, ll b) { a = (a * b) % MOD; }
void qmod(ll &a, ll b, ll c) { a = (b * c) % MOD; }
ll median(ll a, ll b, ll c) {
return a + b + c - max({a, b, c}) - min({a, b, c});
}
void ans1(bool x) {
if (x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool x) {
if (x)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void ans3(bool x) {
if (x)
cout << "Yay!" << endl;
else
cout << ":(" << endl;
}
template <typename T1, typename T2> void ans(bool x, T1 y, T2 z) {
if (x)
cout << y << endl;
else
cout << z << endl;
}
template <typename T> void debug(vector<vector<T>> v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
cout << v[i][0];
for (ll j = 1; j < w; j++)
cout spa v[i][j];
cout << endl;
}
};
void debug(vector<string> v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++)
cout << v[i][j];
cout << endl;
}
};
template <typename T> void debug(vector<T> v, ll n) {
if (n != 0)
cout << v[0];
for (ll i = 1; i < n; i++)
cout spa v[i];
cout << endl;
};
template <typename T> vector<vector<T>> vec(ll x, ll y, T w) {
vector<vector<T>> v(x, vector<T>(y, w));
return v;
}
ll gcd(ll x, ll y) {
ll r;
while (y != 0 && (r = x % y) != 0) {
x = y;
y = r;
}
return y == 0 ? x : y;
}
template <typename T> vector<ll> dx = {1, 0, -1, 0, 1, 1, -1, -1};
vector<ll> dy = {0, 1, 0, -1, 1, -1, 1, -1};
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
template <ll base, ll sz> struct Bits {
vector<ll> data;
ll value;
Bits() { data.assign(sz, 0); };
Bits(ll k) {
data.assign(sz, 0);
build(k);
}
void build(ll k) {
for (ll i = 0; i < sz; i++) {
data[i] = k % base;
k /= base;
}
}
Bits &operator=(const ll k) {
fill(ALL(this->data), 0);
this->build(k);
}
ll operator[](const ll k) { return this->data.at(k); }
ll pow(ll k) {
ll ret = 1;
while (k--)
ret *= base;
return ret;
}
void print() {
for (ll i = sz - 1; i >= 0; i--) {
if (i != sz - 1)
cout << " ";
cout << data[i];
}
cout << endl;
}
vector<ll> count(ll k) {
vector<ll> ret(base);
for (ll i = 0; i < k; i++)
ret[data[i]]++;
return ret;
}
};
using bits = Bits<4, 10>;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
ll res = 0, res1 = INF, res2 = -INF, buf = 0;
bool judge = true;
vector<ll> a(3);
ll n;
cin >> n >> a[0] >> a[1] >> a[2];
vector<ll> l(n);
rep(i, 0, n) cin >> l[i];
bits x;
ll k = x.pow(n);
rep(i, 0, k) {
x = i;
auto v = x.count(n);
if (v[0] == 0 || v[1] == 0 || v[2] == 0)
continue;
vector<ll> sumbuf(4);
rep(i, 0, n) { sumbuf[x[i]] += l[i]; }
ll tmp = (n - 3 - v[3]) * 10;
rep(i, 0, 3) tmp += abs(a[i] - sumbuf[i]);
chmin(res1, tmp);
}
cout << res1 << endl;
return 0;
}
| replace | 163 | 164 | 163 | 164 | 0 | |
p03111 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int N, A, B, C;
vector<int> l;
int dfs(int depth, int La, int Lb, int Lc) {
if (depth == N + 1) {
if (La != 0 && Lb != 0 && Lc != 0) {
return abs(A - La) + abs(Lb - B) + abs(Lc - C) - 30;
}
}
int r1 = dfs(depth + 1, La + l[depth], Lb, Lc) + 10;
int r2 = dfs(depth + 1, La, Lb + l[depth], Lc) + 10;
int r3 = dfs(depth + 1, La, Lb, Lc + l[depth]) + 10;
int r4 = dfs(depth + 1, La, Lb, Lc);
return min(min(r1, r2), min(r3, r4));
}
int main() {
cin >> N >> A >> B >> C;
l.resize(N + 1);
for (int i = 1; i <= N; i++) {
cin >> l[i];
} // 1-indexed
cout << dfs(1, 0, 0, 0) << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int N, A, B, C;
vector<int> l;
int dfs(int depth, int La, int Lb, int Lc) {
if (depth == N + 1) {
if (La != 0 && Lb != 0 && Lc != 0) {
return abs(A - La) + abs(Lb - B) + abs(Lc - C) - 30;
} else {
return (1 << 29);
}
}
int r1 = dfs(depth + 1, La + l[depth], Lb, Lc) + 10;
int r2 = dfs(depth + 1, La, Lb + l[depth], Lc) + 10;
int r3 = dfs(depth + 1, La, Lb, Lc + l[depth]) + 10;
int r4 = dfs(depth + 1, La, Lb, Lc);
return min(min(r1, r2), min(r3, r4));
}
int main() {
cin >> N >> A >> B >> C;
l.resize(N + 1);
for (int i = 1; i <= N; i++) {
cin >> l[i];
} // 1-indexed
cout << dfs(1, 0, 0, 0) << endl;
return 0;
}
| insert | 13 | 13 | 13 | 15 | -11 | |
p03111 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N;
vector<int> L;
int A, B, C;
int ans = 1e9;
void dfs(int depth, int a, int b, int c, int mp) {
if (depth == N) { // ベースケース
if (a > 0 && b > 0 && c > 0) {
mp += abs(a - A) + abs(b - B) + abs(c - C);
ans = min(ans, mp - 30);
} else {
return;
}
}
dfs(depth + 1, a + L[depth], b, c, mp + 10);
dfs(depth + 1, a, b + L[depth], c, mp + 10);
dfs(depth + 1, a, b, c + L[depth], mp + 10);
dfs(depth + 1, a, b, c, mp);
}
int main() {
cin >> N >> A >> B >> C;
L.resize(N);
for (int i = 0; i < N; i++) {
cin >> L[i];
}
dfs(0, 0, 0, 0, 0);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int N;
vector<int> L;
int A, B, C;
int ans = 1e9;
void dfs(int depth, int a, int b, int c, int mp) {
if (depth == N) { // ベースケース
if (a > 0 && b > 0 && c > 0) {
mp += abs(a - A) + abs(b - B) + abs(c - C);
ans = min(ans, mp - 30);
return;
} else {
return;
}
}
dfs(depth + 1, a + L[depth], b, c, mp + 10);
dfs(depth + 1, a, b + L[depth], c, mp + 10);
dfs(depth + 1, a, b, c + L[depth], mp + 10);
dfs(depth + 1, a, b, c, mp);
}
int main() {
cin >> N >> A >> B >> C;
L.resize(N);
for (int i = 0; i < N; i++) {
cin >> L[i];
}
dfs(0, 0, 0, 0, 0);
cout << ans << endl;
return 0;
}
| insert | 14 | 14 | 14 | 15 | -11 | |
p03111 | Python | Time Limit Exceeded | N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
def solve(X):
if not ("1" in X and "2" in X and "3" in X):
return 1e10
MS = [[L[i] for i in range(N) if X[i] == j] for j in "123"]
ret = 1e10
ret = min(ret, solve2(MS[0], A) + solve2(MS[1], B) + solve2(MS[2], C))
ret = min(ret, solve2(MS[0], A) + solve2(MS[2], B) + solve2(MS[1], C))
ret = min(ret, solve2(MS[1], A) + solve2(MS[0], B) + solve2(MS[2], C))
ret = min(ret, solve2(MS[1], A) + solve2(MS[2], B) + solve2(MS[0], C))
ret = min(ret, solve2(MS[2], A) + solve2(MS[0], B) + solve2(MS[1], C))
ret = min(ret, solve2(MS[2], A) + solve2(MS[1], B) + solve2(MS[0], C))
return ret
def solve2(M, target):
def rec(Y, target):
# Y: [1, 0, 0]
if len(Y) == len(M):
if len(set(Y)) == 1 and Y[0] == 0:
return 1e10
sum_M = sum([M[i] for i in range(len(M)) if Y[i] == 1])
return abs(target - sum_M) + 10 * (Y.count(1) - 1)
return min(rec(Y + [0], target), rec(Y + [1], target))
ret = rec([], target)
return ret
ans = 1e10
def rec(X):
global ans
if len(X) == N:
ans = min(ans, solve(X))
return
rec(X + "1")
rec(X + "2")
rec(X + "3")
rec("")
print(ans)
| N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
def solve(X):
if not ("1" in X and "2" in X and "3" in X):
return 1e10
MS = [[L[i] for i in range(N) if X[i] == j] for j in "123"]
ret = 1e10
A_ans = []
B_ans = []
C_ans = []
for i in range(3):
A_ans.append(solve2(MS[i], A))
B_ans.append(solve2(MS[i], B))
C_ans.append(solve2(MS[i], C))
ret = min(ret, A_ans[0] + B_ans[1] + C_ans[2])
ret = min(ret, A_ans[0] + B_ans[2] + C_ans[1])
ret = min(ret, A_ans[1] + B_ans[0] + C_ans[2])
ret = min(ret, A_ans[1] + B_ans[2] + C_ans[0])
ret = min(ret, A_ans[2] + B_ans[0] + C_ans[1])
ret = min(ret, A_ans[2] + B_ans[1] + C_ans[0])
return ret
def solve2(M, target):
def rec(Y, target):
# Y: [1, 0, 0]
if len(Y) == len(M):
if len(set(Y)) == 1 and Y[0] == 0:
return 1e10
sum_M = sum([M[i] for i in range(len(M)) if Y[i] == 1])
return abs(target - sum_M) + 10 * (Y.count(1) - 1)
return min(rec(Y + [0], target), rec(Y + [1], target))
ret = rec([], target)
return ret
ans = 1e10
def rec(X):
global ans
if len(X) == N:
ans = min(ans, solve(X))
return
rec(X + "1")
rec(X + "2")
rec(X + "3")
rec("")
print(ans)
| replace | 10 | 16 | 10 | 23 | TLE | |
p03111 | Python | Runtime Error | from math import inf
from collections import deque
N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
ls.append(int(input()))
ls.sort()
q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
n, mp, a, b, c = q.pop()
if n == N:
if min(a, b, c) == 0:
continue
minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
else:
q.append((n + 1, mp, a, b, c))
q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))
print(minmp)
| try:
from math import inf
except:
inf = float("inf")
from collections import deque
N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
ls.append(int(input()))
ls.sort()
q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
n, mp, a, b, c = q.pop()
if n == N:
if min(a, b, c) == 0:
continue
minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
else:
q.append((n + 1, mp, a, b, c))
q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))
print(minmp)
| replace | 0 | 1 | 0 | 4 | 0 | |
p03111 | Python | Runtime Error | # 入力
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = 10**9
def dfs(cursor, a, b, c): # cursor:カーソル a,b,c:現在の竹の長さ
if cursor == N: # cursorが最後まで行ったら終了する。
return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
# abs(a - A) + abs(b - B) + abs(c - C) - 30 でなぜ30を減じているのかというと、
# dfs(0,0,0)
# dfs(0,0,0,0)で始まる以上、最初に選ばれるa,b,cを決定する際にもコストが10増加してしまうからである。
# また、全探索を行う中で、a,b,cの初期値が0,0,0である以上、a,b,cのどれかが0のまま終了する場合が存在する。
# この場合はa,b,cに竹が対応してないと言えるため、解にはならない、そこで三項演算子を利用して
# その場合についてコストをINFとしている
# 以下は4**Nで展開される再起処理となる。
# カーソルの当たっている竹に対して、(A or B or Cに合成する) or (合成しない)の場合に分ける
no_compound_pattern = dfs(cursor, a, b, c)
compound_a_pattern = dfs(cursor, a + L[cursor], b, c)
compound_b_pattern = dfs(cursor, a, b + L[cursor], c)
compound_c_pattern = dfs(cursor, a, b, c + L[cursor])
# 結果的に以下の値が返るのはそれぞれのパターンのコストが決定されてからなので
# 以下のコードは最終的なコストの最小値
return min(
no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern
)
print(dfs(0, 0, 0, 0))
| # 入力
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = 10**9
def dfs(cursor, a, b, c): # cursor:カーソル a,b,c:現在の竹の長さ
if cursor == N: # cursorが最後まで行ったら終了する。
return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
# abs(a - A) + abs(b - B) + abs(c - C) - 30 でなぜ30を減じているのかというと、
# dfs(0,0,0)
# dfs(0,0,0,0)で始まる以上、最初に選ばれるa,b,cを決定する際にもコストが10増加してしまうからである。
# また、全探索を行う中で、a,b,cの初期値が0,0,0である以上、a,b,cのどれかが0のまま終了する場合が存在する。
# この場合はa,b,cに竹が対応してないと言えるため、解にはならない、そこで三項演算子を利用して
# その場合についてコストをINFとしている
# 以下は4**Nで展開される再起処理となる。
# カーソルの当たっている竹に対して、(A or B or Cに合成する) or (合成しない)の場合に分ける
no_compound_pattern = dfs(cursor + 1, a, b, c)
compound_a_pattern = dfs(cursor + 1, a + L[cursor], b, c) + 10
compound_b_pattern = dfs(cursor + 1, a, b + L[cursor], c) + 10
compound_c_pattern = dfs(cursor + 1, a, b, c + L[cursor]) + 10
# 結果的に以下の値が返るのはそれぞれのパターンのコストが決定されてからなので
# 以下のコードは最終的なコストの最小値
return min(
no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern
)
print(dfs(0, 0, 0, 0))
| replace | 19 | 23 | 19 | 23 | RecursionError: maximum recursion depth exceeded in comparison | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03111/Python/s159461881.py", line 30, in <module>
print(dfs(0, 0, 0, 0))
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03111/Python/s159461881.py", line 20, in dfs
no_compound_pattern = dfs(cursor, a, b, c)
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03111/Python/s159461881.py", line 20, in dfs
no_compound_pattern = dfs(cursor, a, b, c)
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03111/Python/s159461881.py", line 20, in dfs
no_compound_pattern = dfs(cursor, a, b, c)
[Previous line repeated 995 more times]
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03111/Python/s159461881.py", line 9, in dfs
if cursor == N: # cursorが最後まで行ったら終了する。
RecursionError: maximum recursion depth exceeded in comparison
|
p03111 | Python | Runtime Error | import itertools
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
ans = float("inf")
for Lp in itertools.permutations(L):
Lac = tuple(itertools.accumulate((0, *Lp)))
for a in range(1, N - 1):
for b in range(a + 1, N):
for c in range(b + 1, N + 1):
A_MP = 10 * (a - 1) + abs(Lac[a] - Lac[0] - A)
B_MP = 10 * (b - a - 1) + abs(Lac[b] - Lac[a] - B)
C_MP = 10 * (c - b - 1) + abs(Lac[c] - Lac[b] - C)
ans = min(ans, A_MP + B_MP + C_MP)
print(ans)
| import itertools
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
ans = float("inf")
for Lp in itertools.permutations(L):
Lac = tuple(itertools.accumulate(([0] + list(Lp))))
for a in range(1, N - 1):
for b in range(a + 1, N):
for c in range(b + 1, N + 1):
A_MP = 10 * (a - 1) + abs(Lac[a] - Lac[0] - A)
B_MP = 10 * (b - a - 1) + abs(Lac[b] - Lac[a] - B)
C_MP = 10 * (c - b - 1) + abs(Lac[c] - Lac[b] - C)
ans = min(ans, A_MP + B_MP + C_MP)
print(ans)
| replace | 7 | 8 | 7 | 8 | 0 | |
p03111 | Python | Runtime Error | import itertools
N, a, b, c = [int(_) for _ in input().split()]
L = [int(input()) for _ in range(N)]
ans = 10**10
for K in itertools.product(range(4), repeat=N):
A = [[] for _ in range(N)]
for i in range(N):
A[K[i]] += [L[i]]
if len(A[1]) and len(A[2]) and len(A[3]):
cost = 10 * (N - len(A[0]) - 3)
cost += abs(a - sum(A[1]))
cost += abs(b - sum(A[2]))
cost += abs(c - sum(A[3]))
ans = min(cost, ans)
print(ans)
| import itertools
N, a, b, c = [int(_) for _ in input().split()]
L = [int(input()) for _ in range(N)]
ans = 10**10
for K in itertools.product(range(4), repeat=N):
A = [[] for _ in range(4)]
for i in range(N):
A[K[i]] += [L[i]]
if len(A[1]) and len(A[2]) and len(A[3]):
cost = 10 * (N - len(A[0]) - 3)
cost += abs(a - sum(A[1]))
cost += abs(b - sum(A[2]))
cost += abs(c - sum(A[3]))
ans = min(cost, ans)
print(ans)
| replace | 6 | 7 | 6 | 7 | 0 | |
p03111 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
} else
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
int main() {
int N, A, B, C;
cin >> N >> A >> B >> C;
vector<int> l(N);
for (int i = 0; i < N; i++)
cin >> l.at(i);
long long ans = INF;
for (int i = 0; i < pow(4, N); i++) {
long long at = 0, bt = 0, ct = 0;
long long al = 0, bl = 0, cl = 0;
for (int j = 0, p = 1; j < N; j++) {
int Z = (i / p) % 4;
if (Z == 1) {
at++;
al += l.at(j);
} else if (Z == 2) {
bt++;
bl += l.at(j);
} else if (Z == 3) {
ct++;
cl += l.at(j);
}
p *= j;
}
if (at > 0 && bt > 0 && ct > 0) {
long long MP =
(at + bt + ct - 3) * 10 + abs(A - al) + abs(B - bl) + abs(C - cl);
chmin(ans, MP);
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
} else
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
int main() {
int N, A, B, C;
cin >> N >> A >> B >> C;
vector<int> l(N);
for (int i = 0; i < N; i++)
cin >> l.at(i);
long long ans = INF;
for (int i = 0; i < pow(4, N); i++) {
long long at = 0, bt = 0, ct = 0;
long long al = 0, bl = 0, cl = 0;
for (int j = 0, p = 1; j < N; j++) {
int Z = (i / p) % 4;
if (Z == 1) {
at++;
al += l.at(j);
} else if (Z == 2) {
bt++;
bl += l.at(j);
} else if (Z == 3) {
ct++;
cl += l.at(j);
}
p *= 4;
}
if (at > 0 && bt > 0 && ct > 0) {
long long MP =
(at + bt + ct - 3) * 10 + abs(A - al) + abs(B - bl) + abs(C - cl);
chmin(ans, MP);
}
}
cout << ans << endl;
} | replace | 46 | 47 | 46 | 47 | -8 | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <assert.h>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
// #include <unordered_map>
// #include <unordered_set>
// #include <boost/container/static_vector.hpp>
// #include <boost/unordered_set.hpp>
// #include <boost/unordered_map.hpp>
// #include <unistd.h>
// #include <cv.h>
// #include <highgui.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <array>
#include <assert.h>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
// #include <unordered_map>
// #include <unordered_set>
// #include <boost/container/static_vector.hpp>
// #include <boost/unordered_set.hpp>
// #include <boost/unordered_map.hpp>
// #include <unistd.h>
// #include <cv.h>
// #include <highgui.h>
#include <stdlib.h>
#include <time.h>
#include <string>
const int MAX_A = 100000;
const int MAX_B = 100000;
const int MAX_Q = 100000;
// int p_in[MAX_N+1];
long long s[MAX_A + 2], t[MAX_B + 2];
long long X[MAX_Q];
int A, B, Q;
const long long lim = (long long)100000000000;
// bool tmp[MAX_N+1];
long long distance(const long long x, int ls, int lt) {
assert(s[ls] <= x);
assert(t[lt] <= x);
long long ret = lim;
long long tmp = 0;
// 最初左
if (t[lt] <= s[ls]) {
tmp += x - s[ls];
tmp += std::min(s[ls] - t[lt], t[lt + 1] - s[ls]);
} else {
tmp += x - t[lt];
tmp += std::min(t[lt] - s[ls], s[ls + 1] - t[lt]);
}
ret = std::min(tmp, ret);
// 最初右
tmp = 0;
if (s[ls + 1] <= t[lt + 1]) {
tmp += s[ls + 1] - x;
tmp += std::min(t[lt + 1] - s[ls + 1], s[ls + 1] - t[lt]);
} else {
tmp += t[lt + 1] - x;
tmp += std::min(s[ls + 1] - t[lt + 1], t[lt + 1] - s[ls]);
}
ret = std::min(tmp, ret);
return ret;
}
int get_lidx(long long x, long long *loc, int num) {
int lb = 0;
int ub = num;
while (lb + 1 < ub) {
assert(loc[lb] <= x && x < loc[ub]);
int mid = (lb + ub) / 2;
if (loc[mid] <= x) {
lb = mid;
} else {
ub = mid;
}
}
return lb;
}
int main(int argc, char **argv) {
std::cin >> A >> B >> Q;
for (int i = 1; i <= A; i++) {
std::cin >> s[i];
}
for (int i = 1; i <= B; i++) {
std::cin >> t[i];
}
s[0] = -lim;
t[0] = -lim;
s[A + 1] = lim;
t[B + 1] = lim;
for (int i = 1; i <= Q; i++) {
std::cin >> X[i];
}
for (int i = 1; i <= Q; i++) {
int ls = get_lidx(X[i], s, A + 1);
int lt = get_lidx(X[i], t, B + 1);
// std::cout << ls << " " << lt << std::endl;
std::cout << distance(X[i], ls, lt) << std::endl;
}
return 0;
}
| #include <algorithm>
#include <array>
#include <assert.h>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
// #include <unordered_map>
// #include <unordered_set>
// #include <boost/container/static_vector.hpp>
// #include <boost/unordered_set.hpp>
// #include <boost/unordered_map.hpp>
// #include <unistd.h>
// #include <cv.h>
// #include <highgui.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <array>
#include <assert.h>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
// #include <unordered_map>
// #include <unordered_set>
// #include <boost/container/static_vector.hpp>
// #include <boost/unordered_set.hpp>
// #include <boost/unordered_map.hpp>
// #include <unistd.h>
// #include <cv.h>
// #include <highgui.h>
#include <stdlib.h>
#include <time.h>
#include <string>
const int MAX_A = 100000;
const int MAX_B = 100000;
const int MAX_Q = 100000;
// int p_in[MAX_N+1];
long long s[MAX_A + 2], t[MAX_B + 2];
long long X[MAX_Q + 1];
int A, B, Q;
const long long lim = (long long)100000000000;
// bool tmp[MAX_N+1];
long long distance(const long long x, int ls, int lt) {
assert(s[ls] <= x);
assert(t[lt] <= x);
long long ret = lim;
long long tmp = 0;
// 最初左
if (t[lt] <= s[ls]) {
tmp += x - s[ls];
tmp += std::min(s[ls] - t[lt], t[lt + 1] - s[ls]);
} else {
tmp += x - t[lt];
tmp += std::min(t[lt] - s[ls], s[ls + 1] - t[lt]);
}
ret = std::min(tmp, ret);
// 最初右
tmp = 0;
if (s[ls + 1] <= t[lt + 1]) {
tmp += s[ls + 1] - x;
tmp += std::min(t[lt + 1] - s[ls + 1], s[ls + 1] - t[lt]);
} else {
tmp += t[lt + 1] - x;
tmp += std::min(s[ls + 1] - t[lt + 1], t[lt + 1] - s[ls]);
}
ret = std::min(tmp, ret);
return ret;
}
int get_lidx(long long x, long long *loc, int num) {
int lb = 0;
int ub = num;
while (lb + 1 < ub) {
assert(loc[lb] <= x && x < loc[ub]);
int mid = (lb + ub) / 2;
if (loc[mid] <= x) {
lb = mid;
} else {
ub = mid;
}
}
return lb;
}
int main(int argc, char **argv) {
std::cin >> A >> B >> Q;
for (int i = 1; i <= A; i++) {
std::cin >> s[i];
}
for (int i = 1; i <= B; i++) {
std::cin >> t[i];
}
s[0] = -lim;
t[0] = -lim;
s[A + 1] = lim;
t[B + 1] = lim;
for (int i = 1; i <= Q; i++) {
std::cin >> X[i];
}
for (int i = 1; i <= Q; i++) {
int ls = get_lidx(X[i], s, A + 1);
int lt = get_lidx(X[i], t, B + 1);
// std::cout << ls << " " << lt << std::endl;
std::cout << distance(X[i], ls, lt) << std::endl;
}
return 0;
}
| replace | 52 | 53 | 52 | 53 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<long long> shrines, temples;
long long s, t, x, lshrine, rshrine, ltemple, rtemple, ans1, ans2, ans3, ans4,
ans5, ans6, a, b, q;
long long solve(long long c, long long l, long long r) {
while (l != r) {
if (c > shrines[(l + r) / 2]) {
l = (l + r) / 2 + 1;
} else {
r = (l + r) / 2;
}
}
if (shrines[l] > c) {
l--;
}
if (l < 1)
return -10000000001;
return shrines[l];
}
long long solve2(long long c, long long l, long long r) {
while (l != r) {
if (c > shrines[(l + r) / 2]) {
l = (l + r) / 2 + 1;
} else {
r = (l + r) / 2;
}
}
if (shrines[l] < c) {
l++;
}
if (l > a)
return 20000000001;
return shrines[l];
}
long long solve3(long long c, long long l, long long r) {
while (l != r) {
if (c > temples[(l + r) / 2]) {
l = (l + r) / 2 + 1;
} else {
r = (l + r) / 2;
}
}
if (temples[l] > c) {
l--;
}
if (l < 1)
return -10000000001;
return temples[l];
}
long long solve4(long long c, long long l, long long r) {
while (l != r) {
if (c > temples[(l + r) / 2]) {
l = (l + r) / 2 + 1;
} else {
r = (l + r) / 2;
}
}
if (temples[l] < c) {
l++;
}
if (l > b)
return 20000000001;
return temples[l];
}
int main() {
cin >> a >> b >> q;
shrines.push_back(0);
temples.push_back(0);
for (long i = 0; i < a; i++) {
cin >> s;
shrines.push_back(s);
}
for (long i = 0; i < b; i++) {
cin >> t;
temples.push_back(t);
}
sort(shrines.begin(), shrines.end());
sort(temples.begin(), temples.end());
for (long i = 0; i < q; i++) {
cin >> x;
lshrine = solve(x, 1, a);
rshrine = solve2(x, 1, b);
ltemple = solve3(x, 1, a);
rtemple = solve4(x, 1, b);
ans1 = x - min(lshrine, ltemple);
ans2 = max(rshrine, rtemple) - x;
ans3 = (x - lshrine) * 2 + rtemple - x;
ans4 = (x - ltemple) * 2 + rshrine - x;
ans5 = (rtemple - x) * 2 + x - lshrine;
ans6 = (rshrine - x) * 2 + x - ltemple;
ans2 = min(ans1, ans2);
ans3 = min(ans2, ans3);
ans4 = min(ans3, ans4);
ans5 = min(ans4, ans5);
ans6 = min(ans5, ans6);
cout << ans6 << endl;
// cout << lshrine << endl;
// cout << rshrine << endl;
// cout << ltemple << endl;
// cout << rtemple << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<long long> shrines, temples;
long long s, t, x, lshrine, rshrine, ltemple, rtemple, ans1, ans2, ans3, ans4,
ans5, ans6, a, b, q;
long long solve(long long c, long long l, long long r) {
while (l != r) {
if (c > shrines[(l + r) / 2]) {
l = (l + r) / 2 + 1;
} else {
r = (l + r) / 2;
}
}
if (shrines[l] > c) {
l--;
}
if (l < 1)
return -10000000001;
return shrines[l];
}
long long solve2(long long c, long long l, long long r) {
while (l != r) {
if (c > shrines[(l + r) / 2]) {
l = (l + r) / 2 + 1;
} else {
r = (l + r) / 2;
}
}
if (shrines[l] < c) {
l++;
}
if (l > a)
return 20000000001;
return shrines[l];
}
long long solve3(long long c, long long l, long long r) {
while (l != r) {
if (c > temples[(l + r) / 2]) {
l = (l + r) / 2 + 1;
} else {
r = (l + r) / 2;
}
}
if (temples[l] > c) {
l--;
}
if (l < 1)
return -10000000001;
return temples[l];
}
long long solve4(long long c, long long l, long long r) {
while (l != r) {
if (c > temples[(l + r) / 2]) {
l = (l + r) / 2 + 1;
} else {
r = (l + r) / 2;
}
}
if (temples[l] < c) {
l++;
}
if (l > b)
return 20000000001;
return temples[l];
}
int main() {
cin >> a >> b >> q;
shrines.push_back(0);
temples.push_back(0);
for (long i = 0; i < a; i++) {
cin >> s;
shrines.push_back(s);
}
for (long i = 0; i < b; i++) {
cin >> t;
temples.push_back(t);
}
sort(shrines.begin(), shrines.end());
sort(temples.begin(), temples.end());
for (long i = 0; i < q; i++) {
cin >> x;
lshrine = solve(x, 1, a);
rshrine = solve2(x, 1, a);
ltemple = solve3(x, 1, b);
rtemple = solve4(x, 1, b);
ans1 = x - min(lshrine, ltemple);
ans2 = max(rshrine, rtemple) - x;
ans3 = (x - lshrine) * 2 + rtemple - x;
ans4 = (x - ltemple) * 2 + rshrine - x;
ans5 = (rtemple - x) * 2 + x - lshrine;
ans6 = (rshrine - x) * 2 + x - ltemple;
ans2 = min(ans1, ans2);
ans3 = min(ans2, ans3);
ans4 = min(ans3, ans4);
ans5 = min(ans4, ans5);
ans6 = min(ans5, ans6);
cout << ans6 << endl;
// cout << lshrine << endl;
// cout << rshrine << endl;
// cout << ltemple << endl;
// cout << rtemple << endl;
}
return 0;
}
| replace | 93 | 95 | 93 | 95 | 0 | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int, int>
#define pll pair<LL, LL>
#define vi vector<int>
#define vii vector<vi>
const double pi = 3.14159265358979323846264;
const int mod = 1000000007;
LL d(LL a, LL b, LL c) { return abs(b - a) + abs(c - b); }
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
// std::cout << std::fixed;
// std::cout << std::setprecision(12);
// std::cout << std::defaultfloat;
int a, b, q;
cin >> a >> b >> q;
vector<LL> s(a + 3);
vector<LL> t(b + 3);
s[0] = t[0] = -mod * 10001LL;
s[1] = t[1] = -mod * 10000LL;
s[a + 2] = t[b + 2] = mod * 10000LL;
s[a + 3] = t[b + 3] = mod * 10001LL;
FOR(i, 0, a) { cin >> s[i + 2]; }
FOR(j, 0, b) { cin >> t[j + 2]; }
FOR(i, 0, q) {
LL x;
cin >> x;
auto si = lower_bound(s.begin(), s.end(), x) - s.begin();
auto ti = lower_bound(t.begin(), t.end(), x) - t.begin();
if (s[si] == x) {
cout << min(abs(x - t[ti]), abs(x - t[ti - 1])) << endl;
} else if (t[ti] == x) {
cout << min(abs(x - s[si]), abs(x - s[si - 1])) << endl;
} else {
cout << min(min(min(d(x, s[si], t[ti]), d(x, s[si - 1], t[ti - 1])),
min(d(x, s[si - 1], t[ti]), d(x, s[si], t[ti - 1]))),
min(min(d(x, t[ti], s[si]), d(x, t[ti], s[si - 1])),
min(d(x, t[ti - 1], s[si]), d(x, t[ti - 1], s[si - 1]))))
<< endl;
}
}
return 0;
}
| #include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int, int>
#define pll pair<LL, LL>
#define vi vector<int>
#define vii vector<vi>
const double pi = 3.14159265358979323846264;
const int mod = 1000000007;
LL d(LL a, LL b, LL c) { return abs(b - a) + abs(c - b); }
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
// std::cout << std::fixed;
// std::cout << std::setprecision(12);
// std::cout << std::defaultfloat;
int a, b, q;
cin >> a >> b >> q;
vector<LL> s(a + 4);
vector<LL> t(b + 4);
s[0] = t[0] = -mod * 10001LL;
s[1] = t[1] = -mod * 10000LL;
s[a + 2] = t[b + 2] = mod * 10000LL;
s[a + 3] = t[b + 3] = mod * 10001LL;
FOR(i, 0, a) { cin >> s[i + 2]; }
FOR(j, 0, b) { cin >> t[j + 2]; }
FOR(i, 0, q) {
LL x;
cin >> x;
auto si = lower_bound(s.begin(), s.end(), x) - s.begin();
auto ti = lower_bound(t.begin(), t.end(), x) - t.begin();
if (s[si] == x) {
cout << min(abs(x - t[ti]), abs(x - t[ti - 1])) << endl;
} else if (t[ti] == x) {
cout << min(abs(x - s[si]), abs(x - s[si - 1])) << endl;
} else {
cout << min(min(min(d(x, s[si], t[ti]), d(x, s[si - 1], t[ti - 1])),
min(d(x, s[si - 1], t[ti]), d(x, s[si], t[ti - 1]))),
min(min(d(x, t[ti], s[si]), d(x, t[ti], s[si - 1])),
min(d(x, t[ti - 1], s[si]), d(x, t[ti - 1], s[si - 1]))))
<< endl;
}
}
return 0;
}
| replace | 52 | 54 | 52 | 54 | -6 | munmap_chunk(): invalid pointer
|
p03112 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <complex>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A, 0), t(B, 0);
for (int i = 0; i < A; i++)
cin >> s[i];
for (int i = 0; i < B; i++)
cin >> t[i];
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (int i = 0; i < Q; i++) {
ll x;
cin >> x;
ll ans = LLINF;
int sp = lower_bound(s.begin(), s.end(), x) - s.begin();
int tp = lower_bound(t.begin(), t.end(), x) - t.begin();
vector<int> S, T;
if (sp < A)
S.push_back(sp);
if (tp < B)
T.push_back(tp);
if (sp > 0)
S.push_back(sp - 1);
if (tp > 0)
T.push_back(tp - 1);
for (auto ss : S) {
tp = lower_bound(t.begin(), t.end(), s[ss]) - t.begin();
if (tp < B)
T.push_back(tp);
if (tp > 0)
T.push_back(sp);
}
for (auto tt : T) {
sp = lower_bound(s.begin(), s.end(), t[tt]) - s.begin();
if (sp < A)
S.push_back(sp);
if (sp > 0)
S.push_back(sp - 1);
}
for (auto ss : S)
for (auto tt : T) {
ans = min(ans, abs(x - s[ss]) + abs(s[ss] - t[tt]));
}
for (auto tt : T)
for (auto ss : S) {
ans = min(ans, abs(x - t[tt]) + abs(t[tt] - s[ss]));
}
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <assert.h>
#include <complex>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A, 0), t(B, 0);
for (int i = 0; i < A; i++)
cin >> s[i];
for (int i = 0; i < B; i++)
cin >> t[i];
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (int i = 0; i < Q; i++) {
ll x;
cin >> x;
ll ans = LLINF;
int sp = lower_bound(s.begin(), s.end(), x) - s.begin();
int tp = lower_bound(t.begin(), t.end(), x) - t.begin();
vector<int> S, T;
if (sp < A)
S.push_back(sp);
if (tp < B)
T.push_back(tp);
if (sp > 0)
S.push_back(sp - 1);
if (tp > 0)
T.push_back(tp - 1);
for (auto ss : S) {
tp = lower_bound(t.begin(), t.end(), s[ss]) - t.begin();
if (tp < B)
T.push_back(tp);
if (tp > 0)
T.push_back(tp - 1);
}
for (auto tt : T) {
sp = lower_bound(s.begin(), s.end(), t[tt]) - s.begin();
if (sp < A)
S.push_back(sp);
if (sp > 0)
S.push_back(sp - 1);
}
for (auto ss : S)
for (auto tt : T) {
ans = min(ans, abs(x - s[ss]) + abs(s[ss] - t[tt]));
}
for (auto tt : T)
for (auto ss : S) {
ans = min(ans, abs(x - t[tt]) + abs(t[tt] - s[ss]));
}
cout << ans << endl;
}
return 0;
} | replace | 56 | 57 | 56 | 57 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) \
sort(x.begin(), x.end()); \
x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int(i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) \
cerr << "(" << #x << ", " << #y << ") = " \
<< "(" << x << ", " << y << ")" << endl;
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
#define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> void print1(T begin, T end) {
while (begin != end) {
cout << (*begin) << " ";
*begin++;
}
cout << endl;
}
template <typename T> void print2(T Array, int height, int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
cout << " " << Array[i][j];
}
cout << endl;
}
}
void print() { std::cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
std::cerr << head << " ";
print(std::forward<Tail>(tail)...);
}
template <class T> void Add(T &a, const T &b, const T &mod = 1000000007) {
int val = ((a % mod) + (b % mod)) % mod;
if (val < 0) {
val += mod;
}
a = val;
}
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
// ------------------------------------------------------------------------------------------
const int INF = 1e18;
signed main() {
int n, m, q;
cin >> n >> m >> q;
vec<int> x(n), y(n);
rep(i, n) { cin >> x[i]; }
rep(i, m) { cin >> y[i]; }
x.push_back(INF);
x.push_back(-INF);
y.push_back(INF);
y.push_back(-INF);
sort(all(x));
sort(all(y));
while (q--) {
int u;
cin >> u;
int s[2];
int t[2];
s[0] = *lower_bound(all(x), u);
s[1] = *prev(upper_bound(all(x), u));
t[0] = *lower_bound(all(y), u);
t[1] = *prev(upper_bound(all(y), u));
int ans = 8e18;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
chmin(ans, abs(u - s[i]) + abs(s[i] - t[j]));
chmin(ans, abs(u - t[j]) + abs(s[i] - t[j]));
}
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) \
sort(x.begin(), x.end()); \
x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int(i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) \
cerr << "(" << #x << ", " << #y << ") = " \
<< "(" << x << ", " << y << ")" << endl;
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
#define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> void print1(T begin, T end) {
while (begin != end) {
cout << (*begin) << " ";
*begin++;
}
cout << endl;
}
template <typename T> void print2(T Array, int height, int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
cout << " " << Array[i][j];
}
cout << endl;
}
}
void print() { std::cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
std::cerr << head << " ";
print(std::forward<Tail>(tail)...);
}
template <class T> void Add(T &a, const T &b, const T &mod = 1000000007) {
int val = ((a % mod) + (b % mod)) % mod;
if (val < 0) {
val += mod;
}
a = val;
}
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
// ------------------------------------------------------------------------------------------
const int INF = 1e18;
signed main() {
int n, m, q;
cin >> n >> m >> q;
vec<int> x(n), y(m);
rep(i, n) { cin >> x[i]; }
rep(i, m) { cin >> y[i]; }
x.push_back(INF);
x.push_back(-INF);
y.push_back(INF);
y.push_back(-INF);
sort(all(x));
sort(all(y));
while (q--) {
int u;
cin >> u;
int s[2];
int t[2];
s[0] = *lower_bound(all(x), u);
s[1] = *prev(upper_bound(all(x), u));
t[0] = *lower_bound(all(y), u);
t[1] = *prev(upper_bound(all(y), u));
int ans = 8e18;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
chmin(ans, abs(u - s[i]) + abs(s[i] - t[j]));
chmin(ans, abs(u - t[j]) + abs(s[i] - t[j]));
}
}
cout << ans << endl;
}
return 0;
} | replace | 89 | 90 | 89 | 90 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) (v).begin(), (v).end()
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define uniqueV(x) \
sort(x.begin(), x.end()); \
x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int(i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) \
cerr << "(" << #x << ", " << #y << ") = " \
<< "(" << x << ", " << y << ")" << endl;
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
#define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;
const int INF = 1e18;
int A, B, Q;
vector<int> s, t;
int bin(vector<int> v, int key) {
auto check = [&](int mid) -> bool { return v[mid] <= key; };
// [l, r)
int l = 0;
int r = v.size();
while (r - l > 1) {
int mid = (l + r) / 2;
if (check(mid)) {
l = mid;
} else {
r = mid;
}
}
return l;
}
int solve(int x) {
// Right, Leftはxより右にあるか左にあるか
// abs取るのは、値が見つからなかったときの処理をINFで統一させたいから(-INFあるとめんどい)
int sRight = abs(*lower_bound(all(s), x));
// int sLeft = abs(*(upper_bound(all(s), x) - 1));
int sLeft = s[bin(s, x)];
int tRight = abs(*lower_bound(all(t), x));
// int tLeft = abs(*(upper_bound(all(t), x) - 1));
int tLeft = t[bin(t, x)];
int ret = INF;
// (s, t) -> x -> (t, s)
if (sLeft != INF and tLeft != INF) {
chmin(ret, abs(x - min(sLeft, tLeft)));
// dbg2(sLeft, tLeft)
}
// s -> x -> t {
if (sLeft != INF and tRight != INF) {
chmin(ret, min(abs(x - sLeft), abs(x - tRight)) + abs(sLeft - tRight));
// dbg2(sLeft, tRight)
}
// t -> x -> s {
if (tLeft != INF and sRight != INF) {
chmin(ret, min(abs(x - tLeft), abs(x - sRight)) + abs(tLeft - sRight));
// dbg2(tLeft, sRight)
}
// x -> (s, t) -> (t, s)
if (sRight != INF and tRight != INF) {
chmin(ret, abs(max(sRight, tRight) - x));
// dbg2(sRight, tRight)
}
return ret;
}
signed main() {
cin >> A >> B >> Q;
s.resize(A);
t.resize(B);
for (int i = 0; i < A; i++) {
cin >> s[i];
}
for (int i = 0; i < B; i++) {
cin >> t[i];
}
// 番兵を設置すると値が見つからなかったときの処理が楽になる
s.push_back(INF);
s.push_back(-INF);
t.push_back(INF);
t.push_back(-INF);
sort(all(t));
sort(all(s));
while (Q--) {
int x;
cin >> x;
int ans = solve(x);
cout << ans << endl;
// line()
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) (v).begin(), (v).end()
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define uniqueV(x) \
sort(x.begin(), x.end()); \
x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int(i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) \
cerr << "(" << #x << ", " << #y << ") = " \
<< "(" << x << ", " << y << ")" << endl;
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
#define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;
const int INF = 1e18;
int A, B, Q;
vector<int> s, t;
int bin(vector<int> &v, int key) {
auto check = [&](int mid) -> bool { return v[mid] <= key; };
// [l, r)
int l = 0;
int r = v.size();
while (r - l > 1) {
int mid = (l + r) / 2;
if (check(mid)) {
l = mid;
} else {
r = mid;
}
}
return l;
}
int solve(int x) {
// Right, Leftはxより右にあるか左にあるか
// abs取るのは、値が見つからなかったときの処理をINFで統一させたいから(-INFあるとめんどい)
int sRight = abs(*lower_bound(all(s), x));
// int sLeft = abs(*(upper_bound(all(s), x) - 1));
int sLeft = s[bin(s, x)];
int tRight = abs(*lower_bound(all(t), x));
// int tLeft = abs(*(upper_bound(all(t), x) - 1));
int tLeft = t[bin(t, x)];
int ret = INF;
// (s, t) -> x -> (t, s)
if (sLeft != INF and tLeft != INF) {
chmin(ret, abs(x - min(sLeft, tLeft)));
// dbg2(sLeft, tLeft)
}
// s -> x -> t {
if (sLeft != INF and tRight != INF) {
chmin(ret, min(abs(x - sLeft), abs(x - tRight)) + abs(sLeft - tRight));
// dbg2(sLeft, tRight)
}
// t -> x -> s {
if (tLeft != INF and sRight != INF) {
chmin(ret, min(abs(x - tLeft), abs(x - sRight)) + abs(tLeft - sRight));
// dbg2(tLeft, sRight)
}
// x -> (s, t) -> (t, s)
if (sRight != INF and tRight != INF) {
chmin(ret, abs(max(sRight, tRight) - x));
// dbg2(sRight, tRight)
}
return ret;
}
signed main() {
cin >> A >> B >> Q;
s.resize(A);
t.resize(B);
for (int i = 0; i < A; i++) {
cin >> s[i];
}
for (int i = 0; i < B; i++) {
cin >> t[i];
}
// 番兵を設置すると値が見つからなかったときの処理が楽になる
s.push_back(INF);
s.push_back(-INF);
t.push_back(INF);
t.push_back(-INF);
sort(all(t));
sort(all(s));
while (Q--) {
int x;
cin >> x;
int ans = solve(x);
cout << ans << endl;
// line()
}
return 0;
} | replace | 32 | 33 | 32 | 33 | TLE | |
p03112 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll calc(vector<ll> a, vector<ll> b, ll x) {
// vector<ll>a,b;
ll ans = 1e18;
ll d;
// for ( int i = 0; i < 2; i++ ) {
// if ( i == 0 ) a = s,b = t;
// else a = t,b = s;
for (int j = 0; j < 2; j++) {
int apos = lower_bound(a.begin(), a.end(), x) - a.begin();
ll ax = a[apos - j];
for (int k = 0; k < 2; k++) {
int bpos = lower_bound(b.begin(), b.end(), ax) - b.begin();
ll bx = b[bpos - k];
d = abs(x - ax) + abs(ax - bx);
ans = min(ans, d);
}
}
// }
return ans;
}
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A + 2), t(B + 2);
ll x[100010];
s[0] = t[0] = -1e18;
for (int i = 1; i <= A; i++)
cin >> s[i];
for (int i = 1; i <= B; i++)
cin >> t[i];
for (int i = 0; i < Q; i++)
cin >> x[i];
s[A + 1] = 1e18;
t[B + 1] = 1e18;
for (int i = 0; i < Q; i++) {
cout << min(calc(s, t, x[i]), calc(t, s, x[i])) << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll calc(vector<ll> &a, vector<ll> &b, ll x) {
// vector<ll>a,b;
ll ans = 1e18;
ll d;
// for ( int i = 0; i < 2; i++ ) {
// if ( i == 0 ) a = s,b = t;
// else a = t,b = s;
for (int j = 0; j < 2; j++) {
int apos = lower_bound(a.begin(), a.end(), x) - a.begin();
ll ax = a[apos - j];
for (int k = 0; k < 2; k++) {
int bpos = lower_bound(b.begin(), b.end(), ax) - b.begin();
ll bx = b[bpos - k];
d = abs(x - ax) + abs(ax - bx);
ans = min(ans, d);
}
}
// }
return ans;
}
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A + 2), t(B + 2);
ll x[100010];
s[0] = t[0] = -1e18;
for (int i = 1; i <= A; i++)
cin >> s[i];
for (int i = 1; i <= B; i++)
cin >> t[i];
for (int i = 0; i < Q; i++)
cin >> x[i];
s[A + 1] = 1e18;
t[B + 1] = 1e18;
for (int i = 0; i < Q; i++) {
cout << min(calc(s, t, x[i]), calc(t, s, x[i])) << endl;
}
return 0;
}
| replace | 14 | 15 | 14 | 15 | TLE | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b, q;
cin >> a >> b >> q;
vector<int> tem(a, 0), shr(b, 0);
for (int i = 0; i < a; i++) {
cin >> tem[i];
}
for (int i = 0; i < b; i++) {
cin >> shr[i];
}
while (q--) {
int s;
cin >> s;
int ans = 1e17;
int in1 = lower_bound(tem.begin(), tem.end(), s) - tem.begin();
int in2 = in1 - 1;
int in3 = lower_bound(shr.begin(), shr.end(), s) - shr.begin();
int in4 = in3 - 1;
if (in1 < a && in3 < b) {
ans = min(min(shr[in1], tem[in3]) - s + abs(shr[in1] - tem[in3]), ans);
}
if (in2 >= 0 && in3 < b) {
int d1 = abs(shr[in3] - s);
int d2 = abs(s - tem[in2]);
int temp1 = 2LL * d1 + d2;
int temp2 = 2LL * d2 + d1;
ans = min(ans, min(temp1, temp2));
}
if (in2 >= 0 && in4 >= 0) {
ans = min(s - max(shr[in4], tem[in2]) + abs(shr[in4] - tem[in2]), ans);
}
if (in4 >= 0 && in1 < a) {
int d1 = abs(s - shr[in4]);
int d2 = abs(tem[in1] - s);
int temp1 = 2LL * d1 + d2;
int temp2 = 2LL * d2 + d1;
ans = min(ans, min(temp1, temp2));
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b, q;
cin >> a >> b >> q;
vector<int> tem(a, 0), shr(b, 0);
for (int i = 0; i < a; i++) {
cin >> tem[i];
}
for (int i = 0; i < b; i++) {
cin >> shr[i];
}
while (q--) {
int s;
cin >> s;
int ans = 1e17;
int in1 = lower_bound(tem.begin(), tem.end(), s) - tem.begin();
int in2 = in1 - 1;
int in3 = lower_bound(shr.begin(), shr.end(), s) - shr.begin();
int in4 = in3 - 1;
if (in1 < a && in3 < b) {
ans = min(min(shr[in3], tem[in1]) - s + abs(shr[in3] - tem[in1]), ans);
}
if (in2 >= 0 && in3 < b) {
int d1 = abs(shr[in3] - s);
int d2 = abs(s - tem[in2]);
int temp1 = 2LL * d1 + d2;
int temp2 = 2LL * d2 + d1;
ans = min(ans, min(temp1, temp2));
}
if (in2 >= 0 && in4 >= 0) {
ans = min(s - max(shr[in4], tem[in2]) + abs(shr[in4] - tem[in2]), ans);
}
if (in4 >= 0 && in1 < a) {
int d1 = abs(s - shr[in4]);
int d2 = abs(tem[in1] - s);
int temp1 = 2LL * d1 + d2;
int temp2 = 2LL * d2 + d1;
ans = min(ans, min(temp1, temp2));
}
cout << ans << endl;
}
} | replace | 31 | 32 | 31 | 32 | 0 | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep2(x, from, to) for (long long x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
#define INF 10000000000000000
#define debug(x) cout << #x << ": " << x << endl
#define all(x) x.begin(), x.end()
typedef pair<long long, long long> P;
typedef pair<long long, P> PP;
long long a, b, q;
long long s[10007];
long long t[10007];
long long x[10007];
long long now;
long long ss, tt;
long long rs, rt;
long long ans;
int main() {
cin >> a >> b >> q;
rep(i, a) cin >> s[i];
rep(i, b) cin >> t[i];
rep(i, q) cin >> x[i];
s[a] = INF;
t[b] = INF;
rep(i, q) {
ans = INF;
now = x[i];
ss = (long long)(lower_bound(s, s + a + 1, now) - s);
tt = (long long)(lower_bound(t, t + b + 1, now) - t);
//
if (ss != a && tt != b) {
rs = ss;
rt = tt;
ans = min(ans, max(s[rs], t[rt]) - now);
}
//
if (ss != 0 && tt != b) {
rs = ss - 1;
rt = tt;
ans = min(ans, (now - s[rs]) + (t[rt] - now) +
min((now - s[rs]), (t[rt] - now)));
}
//
if (ss != a && tt != 0) {
rs = ss;
rt = tt - 1;
ans = min(ans, (now - t[rt]) + (s[rs] - now) +
min((now - t[rt]), (s[rs] - now)));
}
//
if (ss != 0 && tt != 0) {
rs = ss - 1;
rt = tt - 1;
ans = min(ans, now - min(s[rs], t[rt]));
}
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep2(x, from, to) for (long long x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
#define INF 10000000000000000
#define debug(x) cout << #x << ": " << x << endl
#define all(x) x.begin(), x.end()
typedef pair<long long, long long> P;
typedef pair<long long, P> PP;
long long a, b, q;
long long s[100007];
long long t[100007];
long long x[100007];
long long now;
long long ss, tt;
long long rs, rt;
long long ans;
int main() {
cin >> a >> b >> q;
rep(i, a) cin >> s[i];
rep(i, b) cin >> t[i];
rep(i, q) cin >> x[i];
s[a] = INF;
t[b] = INF;
rep(i, q) {
ans = INF;
now = x[i];
ss = (long long)(lower_bound(s, s + a + 1, now) - s);
tt = (long long)(lower_bound(t, t + b + 1, now) - t);
//
if (ss != a && tt != b) {
rs = ss;
rt = tt;
ans = min(ans, max(s[rs], t[rt]) - now);
}
//
if (ss != 0 && tt != b) {
rs = ss - 1;
rt = tt;
ans = min(ans, (now - s[rs]) + (t[rt] - now) +
min((now - s[rs]), (t[rt] - now)));
}
//
if (ss != a && tt != 0) {
rs = ss;
rt = tt - 1;
ans = min(ans, (now - t[rt]) + (s[rs] - now) +
min((now - t[rt]), (s[rs] - now)));
}
//
if (ss != 0 && tt != 0) {
rs = ss - 1;
rt = tt - 1;
ans = min(ans, now - min(s[rs], t[rt]));
}
cout << ans << endl;
}
return 0;
} | replace | 21 | 24 | 21 | 24 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define BR "\n"
#define SP " "
#define SHOW(x) \
for (int i = 0; i < x.size(); i++) { \
cout << x[i] << SP; \
} \
cout << BR;
#define SHOW2(x) \
for (int j = 0; j < x.size(); j++) { \
SHOW(x[j]); \
} \
cout << BR;
int main() {
ll A, B, Q;
cin >> A >> B >> Q;
ll INF = 1e11;
vector<ll> s(A + 2);
vector<ll> t(B + 2);
for (int i = 1; i <= A; i++) {
cin >> s[i];
}
for (int i = 1; i <= B; i++) {
cin >> t[i];
}
s[0] = -INF, t[0] = -INF;
s[A + 1] = INF, t[A + 1] = INF;
for (int i = 0; i < Q; i++) {
ll x;
cin >> x;
int l, r, m;
l = -1, r = A + 1, m;
while (l + 1 < r) {
m = (l + r) / 2;
if (s[m] <= x) {
l = m;
} else {
r = m;
}
}
int la = l, ra = r;
// cout << SP << la << SP << ra << BR;
l = -1, r = B + 1, m;
while (l + 1 < r) {
m = (l + r) / 2;
if (t[m] <= x) {
l = m;
} else {
r = m;
}
}
int lb = l, rb = r;
// cout << SP << lb << SP << rb << BR;
ll al = abs(x - s[la]), ar = abs(x - s[ra]);
ll bl = abs(x - t[lb]), br = abs(x - t[rb]);
ll ans = min(max(al, bl), max(ar, br));
ans = min(ans, min(al, ar) * 2 + min(bl, br));
ans = min(ans, min(al, ar) + min(bl, br) * 2);
cout << ans << BR;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define BR "\n"
#define SP " "
#define SHOW(x) \
for (int i = 0; i < x.size(); i++) { \
cout << x[i] << SP; \
} \
cout << BR;
#define SHOW2(x) \
for (int j = 0; j < x.size(); j++) { \
SHOW(x[j]); \
} \
cout << BR;
int main() {
ll A, B, Q;
cin >> A >> B >> Q;
ll INF = 1e11;
vector<ll> s(A + 2);
vector<ll> t(B + 2);
for (int i = 1; i <= A; i++) {
cin >> s[i];
}
for (int i = 1; i <= B; i++) {
cin >> t[i];
}
s[0] = -INF, t[0] = -INF;
s[A + 1] = INF, t[B + 1] = INF;
for (int i = 0; i < Q; i++) {
ll x;
cin >> x;
int l, r, m;
l = -1, r = A + 1, m;
while (l + 1 < r) {
m = (l + r) / 2;
if (s[m] <= x) {
l = m;
} else {
r = m;
}
}
int la = l, ra = r;
// cout << SP << la << SP << ra << BR;
l = -1, r = B + 1, m;
while (l + 1 < r) {
m = (l + r) / 2;
if (t[m] <= x) {
l = m;
} else {
r = m;
}
}
int lb = l, rb = r;
// cout << SP << lb << SP << rb << BR;
ll al = abs(x - s[la]), ar = abs(x - s[ra]);
ll bl = abs(x - t[lb]), br = abs(x - t[rb]);
ll ans = min(max(al, bl), max(ar, br));
ans = min(ans, min(al, ar) * 2 + min(bl, br));
ans = min(ans, min(al, ar) + min(bl, br) * 2);
cout << ans << BR;
}
return 0;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI = 3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for (int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int A, B, Q;
cin >> A >> B >> Q;
vs64 sh(A);
rep(i, A) cin >> sh[i];
vs64 te(B);
rep(i, B) cin >> te[i];
vs64 x(Q);
rep(i, Q) cin >> x[i];
sort(sh.begin(), sh.end());
sort(te.begin(), te.end());
vector<pair<s64, s64>> s2t(A);
rep(i, A) {
auto it = lower_bound(te.begin(), te.end(), sh[i]);
if (it == te.begin()) {
s2t[i] = make_pair(sh[i], abs(sh[i] - te[0]));
} else if (it == te.end()) {
s2t[i] = make_pair(sh[i], abs(sh[i] - te[B - 1]));
} else {
int temp = MIN(abs(sh[i] - *it), abs(sh[i] - *(it - 1)));
s2t[i] = make_pair(sh[i], temp);
}
}
vector<pair<s64, s64>> t2s(B);
rep(i, B) {
auto it = lower_bound(sh.begin(), sh.end(), te[i]);
if (it == sh.begin()) {
t2s[i] = make_pair(te[i], abs(te[i] - sh[0]));
} else if (it == sh.end()) {
t2s[i] = make_pair(te[i], abs(te[i] - sh[A - 1]));
} else {
int temp = MIN(abs(te[i] - *it), abs(te[i] - *(it - 1)));
t2s[i] = make_pair(te[i], temp);
}
}
// cout << "s2t\n";
// rep (i, A)
// {
// cout << "s, dis = " << s2t[i].first << ", " << s2t[i].second << "\n";
// }
// cout << "t2s\n";
// rep (i, A)
// {
// cout << "t, dis = " << t2s[i].first << ", " << t2s[i].second << "\n";
// }
s64 ans;
rep(i, Q) {
auto its =
lower_bound(s2t.begin(), s2t.end(), pair<s64, s64>(x[i], -1),
[](const pair<s64, s64> &xx, const pair<s64, s64> &yy) {
return xx.first < yy.first;
});
s64 temps;
if (its == s2t.begin())
temps = abs(x[i] - its->first) + its->second;
else if (its == s2t.end())
temps = abs(x[i] - s2t[A - 1].first) + s2t[A - 1].second;
else {
temps = MIN(abs(x[i] - its->first) + its->second,
abs(x[i] - (its - 1)->first) + (its - 1)->second);
}
auto itt =
lower_bound(t2s.begin(), t2s.end(), pair<s64, s64>(x[i], -1),
[](const pair<s64, s64> &xx, const pair<s64, s64> &yy) {
return xx.first < yy.first;
});
s64 tempt;
if (itt == t2s.begin())
tempt = abs(x[i] - itt->first) + itt->second;
else if (itt == t2s.end())
tempt = abs(x[i] - t2s[A - 1].first) + t2s[A - 1].second;
else {
tempt = MIN(abs(x[i] - itt->first) + itt->second,
abs(x[i] - (itt - 1)->first) + (itt - 1)->second);
}
// cout << "Q" << i << ": " << temps << ", " << tempt << "\n";
ans = MIN(temps, tempt);
cout << ans << "\n";
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI = 3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for (int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int A, B, Q;
cin >> A >> B >> Q;
vs64 sh(A);
rep(i, A) cin >> sh[i];
vs64 te(B);
rep(i, B) cin >> te[i];
vs64 x(Q);
rep(i, Q) cin >> x[i];
sort(sh.begin(), sh.end());
sort(te.begin(), te.end());
vector<pair<s64, s64>> s2t(A);
rep(i, A) {
auto it = lower_bound(te.begin(), te.end(), sh[i]);
if (it == te.begin()) {
s2t[i] = make_pair(sh[i], abs(sh[i] - te[0]));
} else if (it == te.end()) {
s2t[i] = make_pair(sh[i], abs(sh[i] - te[B - 1]));
} else {
int temp = MIN(abs(sh[i] - *it), abs(sh[i] - *(it - 1)));
s2t[i] = make_pair(sh[i], temp);
}
}
vector<pair<s64, s64>> t2s(B);
rep(i, B) {
auto it = lower_bound(sh.begin(), sh.end(), te[i]);
if (it == sh.begin()) {
t2s[i] = make_pair(te[i], abs(te[i] - sh[0]));
} else if (it == sh.end()) {
t2s[i] = make_pair(te[i], abs(te[i] - sh[A - 1]));
} else {
int temp = MIN(abs(te[i] - *it), abs(te[i] - *(it - 1)));
t2s[i] = make_pair(te[i], temp);
}
}
// cout << "s2t\n";
// rep (i, A)
// {
// cout << "s, dis = " << s2t[i].first << ", " << s2t[i].second << "\n";
// }
// cout << "t2s\n";
// rep (i, A)
// {
// cout << "t, dis = " << t2s[i].first << ", " << t2s[i].second << "\n";
// }
s64 ans;
rep(i, Q) {
auto its =
lower_bound(s2t.begin(), s2t.end(), pair<s64, s64>(x[i], -1),
[](const pair<s64, s64> &xx, const pair<s64, s64> &yy) {
return xx.first < yy.first;
});
s64 temps;
if (its == s2t.begin())
temps = abs(x[i] - its->first) + its->second;
else if (its == s2t.end())
temps = abs(x[i] - s2t[A - 1].first) + s2t[A - 1].second;
else {
temps = MIN(abs(x[i] - its->first) + its->second,
abs(x[i] - (its - 1)->first) + (its - 1)->second);
}
auto itt =
lower_bound(t2s.begin(), t2s.end(), pair<s64, s64>(x[i], -1),
[](const pair<s64, s64> &xx, const pair<s64, s64> &yy) {
return xx.first < yy.first;
});
s64 tempt;
if (itt == t2s.begin())
tempt = abs(x[i] - itt->first) + itt->second;
else if (itt == t2s.end())
tempt = abs(x[i] - t2s[B - 1].first) + t2s[B - 1].second;
else {
tempt = MIN(abs(x[i] - itt->first) + itt->second,
abs(x[i] - (itt - 1)->first) + (itt - 1)->second);
}
// cout << "Q" << i << ": " << temps << ", " << tempt << "\n";
ans = MIN(temps, tempt);
cout << ans << "\n";
}
return 0;
}
| replace | 116 | 117 | 116 | 117 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
const ll INF = 1e18 + 18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;
int main() {
ll A, B, Q;
cin >> A >> B >> Q;
vector<ll> S(A), T(B);
rep(i, A) { cin >> S[i]; }
rep(i, B) { cin >> T[i]; }
rep(i, Q) {
ll X;
cin >> X;
auto itrS = lower_bound(ALL(S), X);
auto itrT = lower_bound(ALL(T), X);
ll D, DD, C, CC;
if (*itrS == X) {
D = X;
DD = X;
} else if (itrS == S.begin()) {
D = -1 * INF;
DD = S[0];
} else if (itrS == S.end()) {
D = S[A - 1];
DD = INF;
} else {
DD = *itrS;
itrS--;
D = *itrS;
}
if (*itrT == X) {
C = X;
CC = X;
} else if (itrT == T.begin()) {
C = -1 * INF;
CC = T[0];
} else if (itrT == T.end()) {
C = T[A - 1];
CC = INF;
} else {
CC = *itrT;
itrT--;
C = *itrT;
}
// cout<<D<<" "<<C<<" "<<" "<<CC<<" "<<DD<<endl;
vector<ll> W(6);
W[0] = (CC + X - 2 * D);
W[1] = (2 * CC - X - D);
W[2] = (DD + X - 2 * C);
W[3] = (2 * DD - X - C);
W[4] = X - min(C, D);
W[5] = max(CC, DD) - X;
sort(ALL(W));
cout << W[0] << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
const ll INF = 1e18 + 18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;
int main() {
ll A, B, Q;
cin >> A >> B >> Q;
vector<ll> S(A), T(B);
rep(i, A) { cin >> S[i]; }
rep(i, B) { cin >> T[i]; }
rep(i, Q) {
ll X;
cin >> X;
auto itrS = lower_bound(ALL(S), X);
auto itrT = lower_bound(ALL(T), X);
ll D, DD, C, CC;
if (*itrS == X) {
D = X;
DD = X;
} else if (itrS == S.begin()) {
D = -1 * INF;
DD = S[0];
} else if (itrS == S.end()) {
D = S[A - 1];
DD = INF;
} else {
DD = *itrS;
itrS--;
D = *itrS;
}
if (*itrT == X) {
C = X;
CC = X;
} else if (itrT == T.begin()) {
C = -1 * INF;
CC = T[0];
} else if (itrT == T.end()) {
C = T[B - 1];
CC = INF;
} else {
CC = *itrT;
itrT--;
C = *itrT;
}
// cout<<D<<" "<<C<<" "<<" "<<CC<<" "<<DD<<endl;
vector<ll> W(6);
W[0] = (CC + X - 2 * D);
W[1] = (2 * CC - X - D);
W[2] = (DD + X - 2 * C);
W[3] = (2 * DD - X - C);
W[4] = X - min(C, D);
W[5] = max(CC, DD) - X;
sort(ALL(W));
cout << W[0] << endl;
}
}
| replace | 48 | 49 | 48 | 49 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) \
for (auto x : (V)) \
cout << x << " " << endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template <class T> struct edge {
int from, to;
T cost;
};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline T powerM(T a, T b) {
if (b == 0)
return 1;
T tmp = powerM(a, b / 2);
if (b % 2 == 0)
return tmp * tmp % MOD;
else
return tmp * tmp % MOD * a % MOD;
}
template <class T> inline T power(T a, T b, T m) {
if (b == 0)
return 1;
T tmp = power(a, b / 2, m);
if (b % 2 == 0)
return tmp * tmp % m;
else
return tmp * tmp % m * a % m;
}
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ax+by=gcd(a,b)を解く
template <class T> inline T extgcd(T a, T b, T &x, T &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
T d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
void hey() { cout << "hey" << endl; }
int main() {
int a, b, q;
cin >> a >> b >> q;
vector<ll> s(a), t(b);
rep(i, a) cin >> s[i];
rep(i, b) cin >> t[i];
rep(qq, q) {
ll x;
cin >> x;
// 地点 x から左右に近いもの各々が神社、寺の訪れるものの候補
// 但し地点 x に丁度存在するときはややこしそう
int s1, t1, s2, t2;
if (lower_bound(all(s), x) == s.end()) {
// x 以上には神社は存在しない
s1 = lower_bound(all(s), x) - s.begin() - 1;
s2 = s1;
} else {
s2 = lower_bound(all(s), x) - s.begin(); // x 以上で一番近い神社のindex
// s2 の地点が丁度 x だったり、s2より前の地点が存在しなければs1 = s2
if (s2 == 0 || s[s2] == x)
s1 = s2;
else
s1 = s2 - 1;
}
if (lower_bound(all(t), x) == t.end()) {
t1 = lower_bound(all(t), x) - t.begin() - 1;
t2 = t1;
} else {
t2 = lower_bound(all(s), x) - t.begin(); // x 以上で一番近い寺のindex
if (t2 == 0 || t[t2] == x)
t1 = t2;
else
t1 = t2 - 1;
}
// 特殊な条件を除き、s1,s2は神社に関して、t1,t2は寺に関して、
// 各々x以下、x以上で一番近い地点のindexを表す
// とりあえず(s1,s2)*(t1,t2)を全部調べればいい
ll res = 1000000000000000;
int ss, tt;
rep(i, 2) {
rep(j, 2) {
ss = i == 0 ? s1 : s2;
tt = j == 0 ? t1 : t2;
// s[ss]とt[tt]を両方回るのに必要な移動距離は
ll buf = abs(s[ss] - t[tt]); // 神社⇔寺
buf += min(abs(x - s[ss]),
abs(x - t[tt])); // 神社または寺の近い方にたどり着く
chmin(res, buf);
}
}
cout << res << endl;
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) \
for (auto x : (V)) \
cout << x << " " << endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template <class T> struct edge {
int from, to;
T cost;
};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline T powerM(T a, T b) {
if (b == 0)
return 1;
T tmp = powerM(a, b / 2);
if (b % 2 == 0)
return tmp * tmp % MOD;
else
return tmp * tmp % MOD * a % MOD;
}
template <class T> inline T power(T a, T b, T m) {
if (b == 0)
return 1;
T tmp = power(a, b / 2, m);
if (b % 2 == 0)
return tmp * tmp % m;
else
return tmp * tmp % m * a % m;
}
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ax+by=gcd(a,b)を解く
template <class T> inline T extgcd(T a, T b, T &x, T &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
T d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
void hey() { cout << "hey" << endl; }
int main() {
int a, b, q;
cin >> a >> b >> q;
vector<ll> s(a), t(b);
rep(i, a) cin >> s[i];
rep(i, b) cin >> t[i];
rep(qq, q) {
ll x;
cin >> x;
// 地点 x から左右に近いもの各々が神社、寺の訪れるものの候補
// 但し地点 x に丁度存在するときはややこしそう
int s1, t1, s2, t2;
if (lower_bound(all(s), x) == s.end()) {
// x 以上には神社は存在しない
s1 = lower_bound(all(s), x) - s.begin() - 1;
s2 = s1;
} else {
s2 = lower_bound(all(s), x) - s.begin(); // x 以上で一番近い神社のindex
// s2 の地点が丁度 x だったり、s2より前の地点が存在しなければs1 = s2
if (s2 == 0 || s[s2] == x)
s1 = s2;
else
s1 = s2 - 1;
}
if (lower_bound(all(t), x) == t.end()) {
t1 = lower_bound(all(t), x) - t.begin() - 1;
t2 = t1;
} else {
t2 = lower_bound(all(t), x) - t.begin(); // x 以上で一番近い寺のindex
if (t2 == 0 || t[t2] == x)
t1 = t2;
else
t1 = t2 - 1;
}
// 特殊な条件を除き、s1,s2は神社に関して、t1,t2は寺に関して、
// 各々x以下、x以上で一番近い地点のindexを表す
// とりあえず(s1,s2)*(t1,t2)を全部調べればいい
ll res = 1000000000000000;
int ss, tt;
rep(i, 2) {
rep(j, 2) {
ss = i == 0 ? s1 : s2;
tt = j == 0 ? t1 : t2;
// s[ss]とt[tt]を両方回るのに必要な移動距離は
ll buf = abs(s[ss] - t[tt]); // 神社⇔寺
buf += min(abs(x - s[ss]),
abs(x - t[tt])); // 神社または寺の近い方にたどり着く
chmin(res, buf);
}
}
cout << res << endl;
}
}
| replace | 96 | 97 | 96 | 97 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define INF 2e10
typedef long long llong;
using namespace std;
int main() {
int a, b, q;
cin >> a >> b >> q;
llong s[10002], t[10002];
for (int i = 1; i <= a; ++i)
cin >> s[i];
for (int i = 1; i <= b; ++i)
cin >> t[i];
s[0] = -INF, s[a + 1] = INF;
t[0] = -INF, t[b + 1] = INF;
REP(i, q) {
llong x;
cin >> x;
auto itr_s = lower_bound(s, s + a + 1, x);
auto itr_t = lower_bound(t, t + b + 1, x);
llong ans = INF;
ans = min(ans, max(*itr_s, *itr_t) - x); // 最適の神社と寺がともに東にある時.
ans = min(ans, x - min(*(itr_s - 1),
*(itr_t - 1))); // 最適の神社と寺がともに西にある時.
ans = min(ans, *(itr_t) - *(itr_s - 1) +
min(x - *(itr_s - 1), *(itr_t)-x)); // 西に神社、東に寺.
ans = min(ans, *(itr_s) - *(itr_t - 1) +
min(x - *(itr_t - 1), *(itr_s)-x)); // 西に寺、東に神社.
cout << ans << endl;
}
} // 解説参考. | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define INF 2e10
typedef long long llong;
using namespace std;
int main() {
int a, b, q;
cin >> a >> b >> q;
llong s[100002], t[100002];
for (int i = 1; i <= a; ++i)
cin >> s[i];
for (int i = 1; i <= b; ++i)
cin >> t[i];
s[0] = -INF, s[a + 1] = INF;
t[0] = -INF, t[b + 1] = INF;
REP(i, q) {
llong x;
cin >> x;
auto itr_s = lower_bound(s, s + a + 1, x);
auto itr_t = lower_bound(t, t + b + 1, x);
llong ans = INF;
ans = min(ans, max(*itr_s, *itr_t) - x); // 最適の神社と寺がともに東にある時.
ans = min(ans, x - min(*(itr_s - 1),
*(itr_t - 1))); // 最適の神社と寺がともに西にある時.
ans = min(ans, *(itr_t) - *(itr_s - 1) +
min(x - *(itr_s - 1), *(itr_t)-x)); // 西に神社、東に寺.
ans = min(ans, *(itr_s) - *(itr_t - 1) +
min(x - *(itr_t - 1), *(itr_s)-x)); // 西に寺、東に神社.
cout << ans << endl;
}
} // 解説参考. | replace | 9 | 10 | 9 | 10 | 0 | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf 1e17
using namespace std;
int main() {
speed;
ll a, b, q, x, v;
cin >> a >> b >> q;
set<ll> s, t;
for (int i = 0; i < a; ++i) {
cin >> v;
s.insert(v);
}
for (int i = 0; i < b; ++i) {
cin >> v;
t.insert(v);
}
for (int i = 0; i < q; ++i) {
cin >> x;
auto q = s.lower_bound(x), w = t.lower_bound(x), pq = q, pw = w;
--pq, --pw;
ll ans = inf;
if (q != s.end() && pw != t.end())
ans = min({
ans,
min(*q - x, x - *pw) + *q - *pw,
});
if (pq != s.end() && w != t.end())
ans = min({ans, min(*w - x, x - *pq) + *w - *pq});
if (q != s.end() && w != t.end())
ans = min(ans, max(*w - x, *q - x));
if (pq != s.end() && pw != t.end())
ans = min(ans, max(x - *pw, x - *pq));
cout << ans << '\n';
}
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf 1e17
using namespace std;
int main() {
speed;
ll a, b, q, x, v;
cin >> a >> b >> q;
set<ll> s, t;
for (int i = 0; i < a; ++i) {
cin >> v;
s.insert(v);
}
for (int i = 0; i < b; ++i) {
cin >> v;
t.insert(v);
}
for (int i = 0; i < q; ++i) {
cin >> x;
auto q = s.lower_bound(x), w = t.lower_bound(x), pq = q, pw = w;
if (q == s.begin())
pq = s.end();
else
--pq;
if (w == t.begin())
pw = t.end();
else
--pw;
ll ans = inf;
if (q != s.end() && pw != t.end())
ans = min({
ans,
min(*q - x, x - *pw) + *q - *pw,
});
if (pq != s.end() && w != t.end())
ans = min({ans, min(*w - x, x - *pq) + *w - *pq});
if (q != s.end() && w != t.end())
ans = min(ans, max(*w - x, *q - x));
if (pq != s.end() && pw != t.end())
ans = min(ans, max(x - *pw, x - *pq));
cout << ans << '\n';
}
} | replace | 42 | 43 | 42 | 50 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, q, x;
cin >> a >> b >> q;
vector<long long> s(a), t(a);
for (int i = 0; i < a; i++) {
cin >> s[i];
}
for (int i = 0; i < b; i++) {
cin >> t[i];
}
for (int i = 0; i < q; i++) {
cin >> x;
long long r = a - 1, l = 0, ar, al, br, bl, ans = 1e18;
while (abs(r - l) > 1) { // A
long long mid = (r + l) / 2;
if (s[mid] >= x) {
r = mid;
} else {
l = mid;
}
}
ar = r;
al = r - 1;
if (s[0] > x) {
ar = 0;
al = -1;
}
if (s[a - 1] < x) {
ar = -1;
al = a - 1;
}
r = b - 1;
l = 0;
while (abs(r - l) > 1) { // B
long long mid = (r + l) / 2;
if (t[mid] >= x) {
r = mid;
} else {
l = mid;
}
}
br = r;
bl = r - 1;
if (t[0] > x) {
br = 0;
bl = -1;
}
if (t[b - 1] < x) {
br = -1;
bl = b - 1;
}
if (al >= 0 and bl >= 0)
ans = min(ans, max(abs(x - s[al]), abs(x - t[bl])));
if (ar >= 0 and br >= 0)
ans = min(ans, max(abs(s[ar] - x), abs(t[br] - x)));
if (al >= 0 and br >= 0)
ans = min(ans, 2 * abs(x - s[al]) + abs(t[br] - x));
if (ar >= 0 and bl >= 0)
ans = min(ans, 2 * abs(x - s[ar]) + abs(t[bl] - x));
if (ar >= 0 and bl >= 0)
ans = min(ans, 2 * abs(x - t[bl]) + abs(s[ar] - x));
if (al >= 0 and br >= 0)
ans = min(ans, 2 * abs(x - t[br]) + abs(s[al] - x));
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, q, x;
cin >> a >> b >> q;
vector<long long> s(a), t(b);
for (int i = 0; i < a; i++) {
cin >> s[i];
}
for (int i = 0; i < b; i++) {
cin >> t[i];
}
for (int i = 0; i < q; i++) {
cin >> x;
long long r = a - 1, l = 0, ar, al, br, bl, ans = 1e18;
while (abs(r - l) > 1) { // A
long long mid = (r + l) / 2;
if (s[mid] >= x) {
r = mid;
} else {
l = mid;
}
}
ar = r;
al = r - 1;
if (s[0] > x) {
ar = 0;
al = -1;
}
if (s[a - 1] < x) {
ar = -1;
al = a - 1;
}
r = b - 1;
l = 0;
while (abs(r - l) > 1) { // B
long long mid = (r + l) / 2;
if (t[mid] >= x) {
r = mid;
} else {
l = mid;
}
}
br = r;
bl = r - 1;
if (t[0] > x) {
br = 0;
bl = -1;
}
if (t[b - 1] < x) {
br = -1;
bl = b - 1;
}
if (al >= 0 and bl >= 0)
ans = min(ans, max(abs(x - s[al]), abs(x - t[bl])));
if (ar >= 0 and br >= 0)
ans = min(ans, max(abs(s[ar] - x), abs(t[br] - x)));
if (al >= 0 and br >= 0)
ans = min(ans, 2 * abs(x - s[al]) + abs(t[br] - x));
if (ar >= 0 and bl >= 0)
ans = min(ans, 2 * abs(x - s[ar]) + abs(t[bl] - x));
if (ar >= 0 and bl >= 0)
ans = min(ans, 2 * abs(x - t[bl]) + abs(s[ar] - x));
if (al >= 0 and br >= 0)
ans = min(ans, 2 * abs(x - t[br]) + abs(s[al] - x));
cout << ans << endl;
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
long long s[100000];
long long t[100000];
long long x[100000];
int binary_search(long long a[], int src, int dst, long long key) {
int ok = 0;
int ng = dst;
while (ng - ok > 1) {
int middle = (ok + ng) / 2;
if (a[middle] >= a[key]) {
ok = middle;
} else {
ng = middle;
}
}
return ok;
}
int main() {
int A, B, Q;
std::cin >> A >> B >> Q;
for (int i = 0; i < A; ++i) {
std::cin >> s[i];
}
for (int i = 0; i < B; ++i) {
std::cin >> t[i];
}
for (int i = 0; i < Q; ++i) {
long long ans = 999999999999999999LL;
std::cin >> x[i];
int u = binary_search(s, 0, A, x[i]);
int v = binary_search(t, 0, B, x[i]);
for (int j = std::max(0, u - 10); j < std::min(A, u + 10); ++j) {
for (int k = std::max(0, v - 10); k < std::min(B, v + 10); ++k) {
ans = std::min(ans, std::abs(x[i] - s[j]) + std::abs(s[j] - t[k]));
ans = std::min(ans, std::abs(x[i] - t[k]) + std::abs(t[k] - s[j]));
}
}
std::cout << ans << std::endl;
}
return 0;
}
| #include <bits/stdc++.h>
long long s[100000];
long long t[100000];
long long x[100000];
int binary_search(long long a[], int src, int dst, long long key) {
int ok = 0;
int ng = dst;
while (ng - ok > 1) {
int middle = (ok + ng) / 2;
if (a[middle] <= key) {
ok = middle;
} else {
ng = middle;
}
}
return ok;
}
int main() {
int A, B, Q;
std::cin >> A >> B >> Q;
for (int i = 0; i < A; ++i) {
std::cin >> s[i];
}
for (int i = 0; i < B; ++i) {
std::cin >> t[i];
}
for (int i = 0; i < Q; ++i) {
long long ans = 999999999999999999LL;
std::cin >> x[i];
int u = binary_search(s, 0, A, x[i]);
int v = binary_search(t, 0, B, x[i]);
for (int j = std::max(0, u - 10); j < std::min(A, u + 10); ++j) {
for (int k = std::max(0, v - 10); k < std::min(B, v + 10); ++k) {
ans = std::min(ans, std::abs(x[i] - s[j]) + std::abs(s[j] - t[k]));
ans = std::min(ans, std::abs(x[i] - t[k]) + std::abs(t[k] - s[j]));
}
}
std::cout << ans << std::endl;
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define RANGE(i, n) for (ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
vector<ll> neighbor(vector<ll> arr, ll pos) {
vector<ll> neighbors;
if (pos <= arr[0]) {
neighbors.push_back(arr[0]);
return neighbors;
} else if (pos >= arr.back()) {
neighbors.push_back(arr.back());
return neighbors;
} else {
ll left_id = 0;
ll right_id = arr.size() - 1;
while (right_id - left_id > 1) {
ll mid_id = (left_id + right_id) / 2;
if (arr[mid_id] <= pos)
left_id = mid_id;
else
right_id = mid_id;
}
neighbors.push_back(arr[left_id]);
neighbors.push_back(arr[right_id]);
return neighbors;
}
}
signed main() {
ll A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A);
vector<ll> t(B);
RANGE(i, A) cin >> s[i];
RANGE(i, B) cin >> t[i];
RANGE(i, Q) {
ll x;
cin >> x;
vector<ll> yashiro_cand = neighbor(s, x);
vector<ll> tera_cand = neighbor(t, x);
ll min_route = LLONG_MAX;
for (ll yashiro : yashiro_cand) {
for (ll tera : tera_cand) {
ll route = min(abs(x - yashiro) + abs(yashiro - tera),
abs(x - tera) + abs(tera - yashiro));
min_route = min(min_route, route);
}
}
cout << min_route << endl;
}
}
| #include <bits/stdc++.h>
#define RANGE(i, n) for (ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
vector<ll> neighbor(vector<ll> &arr, ll pos) {
vector<ll> neighbors;
if (pos <= arr[0]) {
neighbors.push_back(arr[0]);
return neighbors;
} else if (pos >= arr.back()) {
neighbors.push_back(arr.back());
return neighbors;
} else {
ll left_id = 0;
ll right_id = arr.size() - 1;
while (right_id - left_id > 1) {
ll mid_id = (left_id + right_id) / 2;
if (arr[mid_id] <= pos)
left_id = mid_id;
else
right_id = mid_id;
}
neighbors.push_back(arr[left_id]);
neighbors.push_back(arr[right_id]);
return neighbors;
}
}
signed main() {
ll A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A);
vector<ll> t(B);
RANGE(i, A) cin >> s[i];
RANGE(i, B) cin >> t[i];
RANGE(i, Q) {
ll x;
cin >> x;
vector<ll> yashiro_cand = neighbor(s, x);
vector<ll> tera_cand = neighbor(t, x);
ll min_route = LLONG_MAX;
for (ll yashiro : yashiro_cand) {
for (ll tera : tera_cand) {
ll route = min(abs(x - yashiro) + abs(yashiro - tera),
abs(x - tera) + abs(tera - yashiro));
min_route = min(min_route, route);
}
}
cout << min_route << endl;
}
}
| replace | 6 | 7 | 6 | 7 | TLE | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
void chmin(long long &a, long long b) {
if (a > b)
a = b;
}
const long long INF = 1LL << 59;
// 前方の index
int former(const vector<long long> &v, long long x) {
return (int)(upper_bound(v.begin(), v.end(), x) - v.begin()) - 1;
}
// 後方の index
int latter(const vector<long long> &v, long long x) {
return (int)(lower_bound(v.begin(), v.end(), x) - v.begin());
}
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<long long> s(A), t(B);
for (int i = 0; i < A; ++i)
cin >> s[i];
for (int i = 0; i < B; ++i)
cin >> t[i];
s.push_back(INF);
s.push_back(-INF);
t.push_back(INF);
t.push_back(-INF);
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (int _ = 0; _ < Q; ++_) {
long long x;
cin >> x;
long long res = INF;
// 最初に s (前方に行くか後方に行くか場合分け)
for (int fl = 0; fl < 2; ++fl) {
int sid = (fl == 0 ? former(s, x) : latter(s, x));
// t の前か後ろか
for (int fl2 = 0; fl2 < 2; ++fl2) {
int tid = (fl2 == 0 ? former(t, s[sid]) : latter(s, s[sid]));
chmin(res, abs(x - s[sid]) + abs(s[sid] - t[tid]));
}
}
// 最初に t (前方に行くか後方に行くか場合分け)
for (int fl = 0; fl < 2; ++fl) {
int tid = (fl == 0 ? former(t, x) : latter(t, x));
// t の前か後ろか
for (int fl2 = 0; fl2 < 2; ++fl2) {
int sid = (fl2 == 0 ? former(s, t[tid]) : latter(s, t[tid]));
chmin(res, abs(x - t[tid]) + abs(t[tid] - s[sid]));
}
}
cout << res << endl;
}
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
void chmin(long long &a, long long b) {
if (a > b)
a = b;
}
const long long INF = 1LL << 59;
// 前方の index
int former(const vector<long long> &v, long long x) {
return (int)(upper_bound(v.begin(), v.end(), x) - v.begin()) - 1;
}
// 後方の index
int latter(const vector<long long> &v, long long x) {
return (int)(lower_bound(v.begin(), v.end(), x) - v.begin());
}
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<long long> s(A), t(B);
for (int i = 0; i < A; ++i)
cin >> s[i];
for (int i = 0; i < B; ++i)
cin >> t[i];
s.push_back(INF);
s.push_back(-INF);
t.push_back(INF);
t.push_back(-INF);
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (int _ = 0; _ < Q; ++_) {
long long x;
cin >> x;
long long res = INF;
// 最初に s (前方に行くか後方に行くか場合分け)
for (int fl = 0; fl < 2; ++fl) {
int sid = (fl == 0 ? former(s, x) : latter(s, x));
// t の前か後ろか
for (int fl2 = 0; fl2 < 2; ++fl2) {
int tid = (fl2 == 0 ? former(t, s[sid]) : latter(t, s[sid]));
chmin(res, abs(x - s[sid]) + abs(s[sid] - t[tid]));
}
}
// 最初に t (前方に行くか後方に行くか場合分け)
for (int fl = 0; fl < 2; ++fl) {
int tid = (fl == 0 ? former(t, x) : latter(t, x));
// t の前か後ろか
for (int fl2 = 0; fl2 < 2; ++fl2) {
int sid = (fl2 == 0 ? former(s, t[tid]) : latter(s, t[tid]));
chmin(res, abs(x - t[tid]) + abs(t[tid] - s[sid]));
}
}
cout << res << endl;
}
} | replace | 45 | 46 | 45 | 46 | 0 | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFF
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define PInt pair<int, int>
#define PLL pair<long long, long long>
#define VInt vector<int>
#define VLL vector<long long>
#define MatrixInt vector<vector<int>>
#define MatrixLL vector<vector<long long>>
typedef long long ll;
using namespace std;
int main() {
int a, b, q;
cin >> a >> b >> q;
VLL s(a, 0), t(b, 0), x(q, 0);
REP(i, a) cin >> s[i];
REP(i, b) cin >> t[i];
REP(i, q) cin >> x[i];
sort(ALL_OF(s));
sort(ALL_OF(t));
REP(i, q) {
int js = lower_bound(ALL_OF(s), x[i]) - s.begin();
int jt = lower_bound(ALL_OF(t), x[i]) - t.begin();
ll ans = 0x7FFFFFFFFFFFFFFFLL;
chmin(ans, abs(s[js] - x[i]) + abs(s[js] - s[jt]));
chmin(ans, abs(t[jt] - x[i]) + abs(s[js] - t[jt]));
if (js > 0) {
chmin(ans, abs(s[js - 1] - x[i]) + abs(s[js - 1] - t[jt]));
chmin(ans, abs(t[jt] - x[i]) + abs(s[js - 1] - t[jt]));
}
if (jt > 0) {
chmin(ans, abs(t[jt - 1] - x[i]) + abs(t[jt - 1] - s[js]));
chmin(ans, abs(s[js] - x[i]) + abs(t[jt - 1] - s[js]));
}
if (js > 0 && jt > 0) {
chmin(ans, abs(t[jt - 1] - x[i]) + abs(t[jt - 1] - s[js - 1]));
chmin(ans, abs(s[js - 1] - x[i]) + abs(t[jt - 1] - s[js - 1]));
}
cout << ans << endl;
}
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFF
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define PInt pair<int, int>
#define PLL pair<long long, long long>
#define VInt vector<int>
#define VLL vector<long long>
#define MatrixInt vector<vector<int>>
#define MatrixLL vector<vector<long long>>
typedef long long ll;
using namespace std;
int main() {
int a, b, q;
cin >> a >> b >> q;
VLL s(a, 0), t(b, 0), x(q, 0);
REP(i, a) cin >> s[i];
REP(i, b) cin >> t[i];
REP(i, q) cin >> x[i];
sort(ALL_OF(s));
sort(ALL_OF(t));
REP(i, q) {
int js = lower_bound(ALL_OF(s), x[i]) - s.begin();
int jt = lower_bound(ALL_OF(t), x[i]) - t.begin();
ll ans = 0x7FFFFFFFFFFFFFFFLL;
chmin(ans, abs(s[js] - x[i]) + abs(s[js] - t[jt]));
chmin(ans, abs(t[jt] - x[i]) + abs(s[js] - t[jt]));
if (js > 0) {
chmin(ans, abs(s[js - 1] - x[i]) + abs(s[js - 1] - t[jt]));
chmin(ans, abs(t[jt] - x[i]) + abs(s[js - 1] - t[jt]));
}
if (jt > 0) {
chmin(ans, abs(t[jt - 1] - x[i]) + abs(t[jt - 1] - s[js]));
chmin(ans, abs(s[js] - x[i]) + abs(t[jt - 1] - s[js]));
}
if (js > 0 && jt > 0) {
chmin(ans, abs(t[jt - 1] - x[i]) + abs(t[jt - 1] - s[js - 1]));
chmin(ans, abs(s[js - 1] - x[i]) + abs(t[jt - 1] - s[js - 1]));
}
cout << ans << endl;
}
} | replace | 65 | 66 | 65 | 66 | 0 | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define INF 1e14 + 1
typedef long long ll;
template <class T> int former(const vector<T> &v, T x) {
return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T> int latter(const vector<T> &v, T x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
int main() {
ll A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A), t(B), xx(Q);
for (int i = 0; i < A; i++)
cin >> s[i];
for (int i = 0; i < B; i++)
cin >> t[i];
for (int i = 0; i < Q; i++)
cin >> xx[i];
s.push_back(INF);
s.push_back(-INF);
t.push_back(INF);
t.push_back(-INF);
sort(t.begin(), t.end());
sort(s.begin(), s.end());
for (int i = 0; i < Q; i++) {
long long x = xx[i];
long long res = INF;
for (int i = 0; i < 2; i++) {
long long first = (i ? s[former(s, x)] : s[latter(s, x)]);
for (int j = 0; j < 2; j++) {
long long second = (j ? t[former(t, first)] : t[latter(t, first)]);
res = min(res, abs(x - first) + abs(first - second));
}
}
for (int i = 0; i < 2; i++) {
long long first = (i ? t[former(s, x)] : t[latter(s, x)]);
for (int j = 0; j < 2; j++) {
long long second = (j ? s[former(s, first)] : s[latter(s, first)]);
res = min(res, abs(x - first) + abs(first - second));
}
}
cout << res << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define INF 1e14 + 1
typedef long long ll;
template <class T> int former(const vector<T> &v, T x) {
return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T> int latter(const vector<T> &v, T x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
int main() {
ll A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A), t(B), xx(Q);
for (int i = 0; i < A; i++)
cin >> s[i];
for (int i = 0; i < B; i++)
cin >> t[i];
for (int i = 0; i < Q; i++)
cin >> xx[i];
s.push_back(INF);
s.push_back(-INF);
t.push_back(INF);
t.push_back(-INF);
sort(t.begin(), t.end());
sort(s.begin(), s.end());
for (int i = 0; i < Q; i++) {
long long x = xx[i];
long long res = INF;
for (int i = 0; i < 2; i++) {
long long first = (i ? s[former(s, x)] : s[latter(s, x)]);
for (int j = 0; j < 2; j++) {
long long second = (j ? t[former(t, first)] : t[latter(t, first)]);
res = min(res, abs(x - first) + abs(first - second));
}
}
for (int i = 0; i < 2; i++) {
long long first = (i ? t[former(t, x)] : t[latter(t, x)]);
for (int j = 0; j < 2; j++) {
long long second = (j ? s[former(s, first)] : s[latter(s, first)]);
res = min(res, abs(x - first) + abs(first - second));
}
}
cout << res << endl;
}
}
| replace | 48 | 49 | 48 | 49 | 0 | |
p03112 | C++ | Runtime Error | /*
ABC119-D
問題
A社の神社とB軒の寺がある。
西からi社目の神社はsiメートル、i軒目の寺はtiメートルの地点
があります。
以下Q個の問いに答える。
問i:道路のxiメートルの地点から出発して自由に移動したとき、
神社1社と寺1軒に訪れるのに必要な最小の移動距離は何メートルか。
制約
1<=A,B<=10^5
1<=Q<=10^5
1<=si,ti,xi<=10^10
方針
単純にxiに一番近い神社と寺に行くのが最短距離なのはわかる。
ただし、パターンとしては以下があるので、全パターン試す。
・最初に前方最寄りの神社に行き、前方最寄りの寺にいく
・最初に前方最寄りの神社に行き、後方最寄りの寺にいく
・最初に後方最寄りの神社に行き、前方最寄りの寺にいく
・最初に後方最寄りの神社に行き、後方最寄りの寺にいく
・最初に前方最寄りの寺に行き、前方最寄りの神社にいく
・最初に前方最寄りの寺に行き、後方最寄りの神社にいく
・最初に後方最寄りの寺に行き、前方最寄りの神社にいく
・最初に後方最寄りの寺に行き、後方最寄りの神社にいく
最寄りを調べるためには以下の二分探索を用いる(O(logN))
lower_bound
・探索したい値以上が現れる最初の位置のイテレータ
v ={1,2,3,4,5} x = 3だったら、index:2の位置のイテレータ
upper_bound
・探索したい値より大きい値が現れる最初の位置のイテレータ
v ={1,2,3,4,5} x = 3だったら、index:3の位置のイテレータ
・前方のindex(自分自身を含む)
upper_bound(v.begin(), v.end(), x) - v.begin() - 1
・前方のindex(自分自身を含まない)
lower_bound(v.begin(), v.end(), x) - v.begin() - 1
・後方のindex(自分自身を含む)
lower_bound(v.begin(), v.end(), x) - v.begin()
・後方のindex(自分自身を含まない)
upper_bound(v.begin(), v.end(), x) - v.begin()
*/
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A), t(B), x(Q);
rep(i, A) cin >> s[i];
rep(i, B) cin >> t[i];
sort(s.begin(), s.end());
sort(t.begin(), t.end());
rep(i, Q) cin >> x[i];
rep(i, Q) {
ll ng = -1;
ll ok = s.size();
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
auto f = [&](ll mid) { return s[mid] > x[i]; };
if (f(mid))
ok = mid;
else
ng = mid;
}
int s_right = min(ok, (ll)(s.size() - 1));
ng = -1;
ok = t.size();
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
auto f = [&](ll mid) { return t[mid] > x[i]; };
if (f(mid))
ok = mid;
else
ng = mid;
}
int t_right = min(ok, (ll)(t.size() - 1));
ll s_distances[2];
s_distances[0] = s[max(0, s_right - 1)];
s_distances[1] = s[s_right];
ll t_distances[2];
t_distances[0] = t[max(0, s_right - 1)];
t_distances[1] = t[t_right];
ll ans = INF;
for (int j = 0; j < 2; j++) {
ans = min(ans, abs(x[i] - s_distances[j]) +
abs(s_distances[j] - t_distances[j]));
ans = min(ans, abs(x[i] - s_distances[j]) +
abs(s_distances[j] - t_distances[(j + 1) % 2]));
}
for (int j = 0; j < 2; j++) {
ans = min(ans, abs(x[i] - t_distances[j]) +
abs(t_distances[j] - s_distances[j]));
ans = min(ans, abs(x[i] - t_distances[j]) +
abs(t_distances[j] - s_distances[(j + 1) % 2]));
}
// coutを遅いので、クエリが多い場合はprintfを使用
printf("%lld\n", ans);
}
} | /*
ABC119-D
問題
A社の神社とB軒の寺がある。
西からi社目の神社はsiメートル、i軒目の寺はtiメートルの地点
があります。
以下Q個の問いに答える。
問i:道路のxiメートルの地点から出発して自由に移動したとき、
神社1社と寺1軒に訪れるのに必要な最小の移動距離は何メートルか。
制約
1<=A,B<=10^5
1<=Q<=10^5
1<=si,ti,xi<=10^10
方針
単純にxiに一番近い神社と寺に行くのが最短距離なのはわかる。
ただし、パターンとしては以下があるので、全パターン試す。
・最初に前方最寄りの神社に行き、前方最寄りの寺にいく
・最初に前方最寄りの神社に行き、後方最寄りの寺にいく
・最初に後方最寄りの神社に行き、前方最寄りの寺にいく
・最初に後方最寄りの神社に行き、後方最寄りの寺にいく
・最初に前方最寄りの寺に行き、前方最寄りの神社にいく
・最初に前方最寄りの寺に行き、後方最寄りの神社にいく
・最初に後方最寄りの寺に行き、前方最寄りの神社にいく
・最初に後方最寄りの寺に行き、後方最寄りの神社にいく
最寄りを調べるためには以下の二分探索を用いる(O(logN))
lower_bound
・探索したい値以上が現れる最初の位置のイテレータ
v ={1,2,3,4,5} x = 3だったら、index:2の位置のイテレータ
upper_bound
・探索したい値より大きい値が現れる最初の位置のイテレータ
v ={1,2,3,4,5} x = 3だったら、index:3の位置のイテレータ
・前方のindex(自分自身を含む)
upper_bound(v.begin(), v.end(), x) - v.begin() - 1
・前方のindex(自分自身を含まない)
lower_bound(v.begin(), v.end(), x) - v.begin() - 1
・後方のindex(自分自身を含む)
lower_bound(v.begin(), v.end(), x) - v.begin()
・後方のindex(自分自身を含まない)
upper_bound(v.begin(), v.end(), x) - v.begin()
*/
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A), t(B), x(Q);
rep(i, A) cin >> s[i];
rep(i, B) cin >> t[i];
sort(s.begin(), s.end());
sort(t.begin(), t.end());
rep(i, Q) cin >> x[i];
rep(i, Q) {
ll ng = -1;
ll ok = s.size();
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
auto f = [&](ll mid) { return s[mid] > x[i]; };
if (f(mid))
ok = mid;
else
ng = mid;
}
int s_right = min(ok, (ll)(s.size() - 1));
ng = -1;
ok = t.size();
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
auto f = [&](ll mid) { return t[mid] > x[i]; };
if (f(mid))
ok = mid;
else
ng = mid;
}
int t_right = min(ok, (ll)(t.size() - 1));
ll s_distances[2];
s_distances[0] = s[max(0, s_right - 1)];
s_distances[1] = s[s_right];
ll t_distances[2];
t_distances[0] = t[max(0, t_right - 1)];
t_distances[1] = t[t_right];
ll ans = INF;
for (int j = 0; j < 2; j++) {
ans = min(ans, abs(x[i] - s_distances[j]) +
abs(s_distances[j] - t_distances[j]));
ans = min(ans, abs(x[i] - s_distances[j]) +
abs(s_distances[j] - t_distances[(j + 1) % 2]));
}
for (int j = 0; j < 2; j++) {
ans = min(ans, abs(x[i] - t_distances[j]) +
abs(t_distances[j] - s_distances[j]));
ans = min(ans, abs(x[i] - t_distances[j]) +
abs(t_distances[j] - s_distances[(j + 1) % 2]));
}
// coutを遅いので、クエリが多い場合はprintfを使用
printf("%lld\n", ans);
}
} | replace | 111 | 112 | 111 | 112 | 0 | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <vector>
using namespace std;
int A, B, Q;
vector<long long> s, t, x;
int main() {
cin >> A >> B >> Q;
s.resize(A + 2);
t.resize(B + 2);
x.resize(Q);
s[0] = LLONG_MIN / 4;
s[A + 1] = LLONG_MAX / 4;
t[0] = LLONG_MIN / 4;
s[B + 1] = LLONG_MAX / 4;
for (int i = 1; i <= A; i++)
cin >> s[i];
for (int i = 1; i <= B; i++)
cin >> t[i];
for (int i = 0; i < Q; i++)
cin >> x[i];
long long s_n[2], t_n[2];
long long ans, d1, d2;
for (int i = 0; i < Q; i++) {
auto it = lower_bound(s.begin(), s.end(), x[i]);
s_n[1] = it - s.begin();
s_n[0] = s_n[1] - 1;
it = lower_bound(t.begin(), t.end(), x[i]);
t_n[1] = it - t.begin();
t_n[0] = t_n[1] - 1;
ans = LLONG_MAX / 2;
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
d1 = abs(x[i] - s[s_n[j]]) + abs(s[s_n[j]] - t[t_n[k]]);
d2 = abs(x[i] - t[t_n[j]]) + abs(t[t_n[j]] - s[s_n[k]]);
ans = min({ans, d1, d2});
}
}
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <vector>
using namespace std;
int A, B, Q;
vector<long long> s, t, x;
int main() {
cin >> A >> B >> Q;
s.resize(A + 2);
t.resize(B + 2);
x.resize(Q);
s[0] = LLONG_MIN / 4;
s[A + 1] = LLONG_MAX / 4;
t[0] = LLONG_MIN / 4;
t[B + 1] = LLONG_MAX / 4;
for (int i = 1; i <= A; i++)
cin >> s[i];
for (int i = 1; i <= B; i++)
cin >> t[i];
for (int i = 0; i < Q; i++)
cin >> x[i];
long long s_n[2], t_n[2];
long long ans, d1, d2;
for (int i = 0; i < Q; i++) {
auto it = lower_bound(s.begin(), s.end(), x[i]);
s_n[1] = it - s.begin();
s_n[0] = s_n[1] - 1;
it = lower_bound(t.begin(), t.end(), x[i]);
t_n[1] = it - t.begin();
t_n[0] = t_n[1] - 1;
ans = LLONG_MAX / 2;
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
d1 = abs(x[i] - s[s_n[j]]) + abs(s[s_n[j]] - t[t_n[k]]);
d2 = abs(x[i] - t[t_n[j]]) + abs(t[t_n[j]] - s[s_n[k]]);
ans = min({ans, d1, d2});
}
}
cout << ans << endl;
}
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
/*----------------------------------ここからマクロ----------------------------------*/
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vecin(a) rep(i, a.size()) cin >> a[i]
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for (int i = 0; i < (int)n; ++i)
#define rep2(i, n) for (int i = 0; i < (int)n; ++i)
#define rep3(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rep4(i, a, b, c) for (int i = (int)a; i < (int)b; i += (int)c)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#ifdef _DEBUG
#define debug1(a) cerr << #a << ": " << a << "\n"
#define debug2(a, b) cerr << #a << ": " << a << ", " << #b << ": " << b << "\n"
#define debug3(a, b, c) \
cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " \
<< c << "\n"
#define debug4(a, b, c, d) \
cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " \
<< c << ", " << #d << ": " << d << "\n"
#define debug(...) \
overload4(__VA_ARGS__, debug4, debug3, debug2, debug1)(__VA_ARGS__)
#define vecout(a) \
cerr << #a << ": ["; \
rep(i, a.size()) { \
cout << a[i]; \
cout << (i == a.size() - 1 ? "" : ","); \
} \
cerr << "]\n"
#else
#define debug(...)
#define vecout(a)
#endif
#define mp make_pair
// #define doset(x) cout << fixed << setprecision(x)
struct doset {
doset(int n) {
cout << fixed << setprecision(n);
cerr << fixed << setprecision(n);
}
};
struct myset {
myset() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
};
using ll = long long;
using ld = long double;
using dou = double;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod1 = 1000000007LL;
const ll mod2 = 998244353LL;
typedef pair<ll, ll> P;
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool change(T &a, U &b) {
if (a > b) {
swap(a, b);
return 1;
}
return 0;
}
// nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n, ll m, ll MOD) {
if (m == 0)
return 1;
if (m < 0)
return -1;
ll res = 1;
while (m) {
if (m & 1)
res = (res * n) % MOD;
m >>= 1;
n *= n;
n %= MOD;
}
return res;
}
ll mypow(ll n, ll m) {
if (m == 0)
return 1;
if (m < 0)
return -1;
ll res = 1;
while (m) {
if (m & 1)
res = (res * n);
m >>= 1;
n *= n;
}
return res;
}
// 素数判定O(sqrt(N))
template <class T> inline bool isp(T n) {
bool res = true;
if (n == 1 || n == 0)
return false;
else {
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res = false;
break;
}
}
return res;
}
}
template <class T = int> T in() {
T x;
cin >> x;
return x;
}
inline bool Yes(bool b) {
cout << (b ? "Yes\n" : "No\n");
return b;
}
inline bool YES(bool b) {
cout << (b ? "YES\n" : "NO\n");
return b;
}
/*----------------------------------マクロここまで----------------------------------*/
ll D(vector<ll> V, ll p) { return *(upper_bound(all(V), p) - 1); }
ll U(vector<ll> V, ll p) { return *lower_bound(all(V), p); }
int main() {
myset m;
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> veca(A + 2), vecb(B + 2), query(Q);
rep(i, A) cin >> veca[i + 1];
rep(i, B) cin >> vecb[i + 1];
rep(i, Q) cin >> query[i];
veca[0] = -INF;
veca.back() = INF;
vecb[0] = -INF;
vecb.back() = INF;
rep(i, Q) {
ll ans = INF, from = query[i], fc, sc, ua = U(veca, from),
ub = U(vecb, from), da = D(veca, from), db = D(vecb, from);
// UU
fc = ua;
sc = U(vecb, fc);
if (!(fc == INF || sc == INF))
chmin(ans, sc - from);
fc = ub;
sc = U(veca, fc);
if (!(fc == INF || sc == INF))
chmin(ans, sc - from);
// UD
fc = ua;
sc = D(vecb, fc);
if (!(fc == INF || sc == -INF))
chmin(ans, fc - from + fc - sc);
fc = ub;
sc = D(veca, fc);
if (!(fc == INF || sc == -INF))
chmin(ans, fc - from + fc - sc);
// DU
fc = da;
sc = U(vecb, fc);
if (!(fc == -INF || sc == INF))
chmin(ans, from - fc + sc - fc);
fc = db;
sc = U(veca, fc);
if (!(fc == -INF || sc == INF))
chmin(ans, from - fc + sc - fc);
// DD
fc = da;
sc = D(vecb, fc);
if (!(fc == -INF || sc == -INF))
chmin(ans, from - sc);
fc = db;
sc = D(veca, fc);
if (!(fc == -INF || sc == -INF))
chmin(ans, from - sc);
cout << ans << "\n";
}
}
| #include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
/*----------------------------------ここからマクロ----------------------------------*/
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vecin(a) rep(i, a.size()) cin >> a[i]
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for (int i = 0; i < (int)n; ++i)
#define rep2(i, n) for (int i = 0; i < (int)n; ++i)
#define rep3(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rep4(i, a, b, c) for (int i = (int)a; i < (int)b; i += (int)c)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#ifdef _DEBUG
#define debug1(a) cerr << #a << ": " << a << "\n"
#define debug2(a, b) cerr << #a << ": " << a << ", " << #b << ": " << b << "\n"
#define debug3(a, b, c) \
cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " \
<< c << "\n"
#define debug4(a, b, c, d) \
cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " \
<< c << ", " << #d << ": " << d << "\n"
#define debug(...) \
overload4(__VA_ARGS__, debug4, debug3, debug2, debug1)(__VA_ARGS__)
#define vecout(a) \
cerr << #a << ": ["; \
rep(i, a.size()) { \
cout << a[i]; \
cout << (i == a.size() - 1 ? "" : ","); \
} \
cerr << "]\n"
#else
#define debug(...)
#define vecout(a)
#endif
#define mp make_pair
// #define doset(x) cout << fixed << setprecision(x)
struct doset {
doset(int n) {
cout << fixed << setprecision(n);
cerr << fixed << setprecision(n);
}
};
struct myset {
myset() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
};
using ll = long long;
using ld = long double;
using dou = double;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod1 = 1000000007LL;
const ll mod2 = 998244353LL;
typedef pair<ll, ll> P;
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool change(T &a, U &b) {
if (a > b) {
swap(a, b);
return 1;
}
return 0;
}
// nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n, ll m, ll MOD) {
if (m == 0)
return 1;
if (m < 0)
return -1;
ll res = 1;
while (m) {
if (m & 1)
res = (res * n) % MOD;
m >>= 1;
n *= n;
n %= MOD;
}
return res;
}
ll mypow(ll n, ll m) {
if (m == 0)
return 1;
if (m < 0)
return -1;
ll res = 1;
while (m) {
if (m & 1)
res = (res * n);
m >>= 1;
n *= n;
}
return res;
}
// 素数判定O(sqrt(N))
template <class T> inline bool isp(T n) {
bool res = true;
if (n == 1 || n == 0)
return false;
else {
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res = false;
break;
}
}
return res;
}
}
template <class T = int> T in() {
T x;
cin >> x;
return x;
}
inline bool Yes(bool b) {
cout << (b ? "Yes\n" : "No\n");
return b;
}
inline bool YES(bool b) {
cout << (b ? "YES\n" : "NO\n");
return b;
}
/*----------------------------------マクロここまで----------------------------------*/
ll D(vector<ll> &V, ll p) { return *(upper_bound(all(V), p) - 1); }
ll U(vector<ll> &V, ll p) { return *lower_bound(all(V), p); }
int main() {
myset m;
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> veca(A + 2), vecb(B + 2), query(Q);
rep(i, A) cin >> veca[i + 1];
rep(i, B) cin >> vecb[i + 1];
rep(i, Q) cin >> query[i];
veca[0] = -INF;
veca.back() = INF;
vecb[0] = -INF;
vecb.back() = INF;
rep(i, Q) {
ll ans = INF, from = query[i], fc, sc, ua = U(veca, from),
ub = U(vecb, from), da = D(veca, from), db = D(vecb, from);
// UU
fc = ua;
sc = U(vecb, fc);
if (!(fc == INF || sc == INF))
chmin(ans, sc - from);
fc = ub;
sc = U(veca, fc);
if (!(fc == INF || sc == INF))
chmin(ans, sc - from);
// UD
fc = ua;
sc = D(vecb, fc);
if (!(fc == INF || sc == -INF))
chmin(ans, fc - from + fc - sc);
fc = ub;
sc = D(veca, fc);
if (!(fc == INF || sc == -INF))
chmin(ans, fc - from + fc - sc);
// DU
fc = da;
sc = U(vecb, fc);
if (!(fc == -INF || sc == INF))
chmin(ans, from - fc + sc - fc);
fc = db;
sc = U(veca, fc);
if (!(fc == -INF || sc == INF))
chmin(ans, from - fc + sc - fc);
// DD
fc = da;
sc = D(vecb, fc);
if (!(fc == -INF || sc == -INF))
chmin(ans, from - sc);
fc = db;
sc = D(veca, fc);
if (!(fc == -INF || sc == -INF))
chmin(ans, from - sc);
cout << ans << "\n";
}
}
| replace | 147 | 149 | 147 | 149 | TLE | |
p03112 | C++ | Runtime Error | /*
How to lambda
ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound of 2
1 2 2 2 3 3
^lb ^ub */
#include <cstdio>
#define BR "\n"
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define ALL(cont) begin(cont), end(cont)
#define AS_MOD(a, b) ((((a) % (b)) + (b)) % (b))
#define FEACH(it, cont) for (auto(it) = begin(cont); it != end(cont); ++it)
#define FEACHR(it, cont) for (auto(it) = rbegin(cont); it != rend(cont); ++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V = max(V, T)
using namespace std;
typedef long long ll;
typedef long double ld;
int A, B, Q;
ll As[100000 + 10];
ll Bs[100000 + 10];
ll INF = (ll)1000 * 1000 * 1000 * 1000;
ll min(ll a, ll b) { return a > b ? b : a; }
ll abs(ll a) { return a > 0 ? a : -a; }
ll *lower_bound(ll *a, ll *b, ll v) {
while (b > a + 1) {
ll *m = a + (b - a) / 2;
if (*m >= v) {
b = m;
} else {
a = m;
}
}
return b;
}
char buf[1 << 20];
int p = 0;
inline char my_get_char() { return buf[p++]; }
#define getchar_unlocked my_get_char
ll fastGet() {
ll ret = 0;
char c = getchar_unlocked();
// skipping
while (c < '0' || c > '9')
c = getchar_unlocked();
do {
ret = (ret << 3) + (ret << 1);
ret += (c - '0');
c = getchar_unlocked();
} while (c >= '0' && c <= '9');
return ret;
}
void fastPut(ll v) {
char s[256];
int p = 0;
do {
s[p++] = (v % 10) + '0';
v /= 10;
} while (v > 0);
while (p--)
putchar_unlocked(s[p]);
}
int main() {
fread(buf, 1, sizeof(buf), stdin);
A = fastGet();
B = fastGet();
Q = fastGet();
As[0] = -INF;
Bs[0] = -INF;
As[A + 1] = INF;
Bs[B + 1] = INF;
REP(i, A)
As[i + 1] = fastGet();
REP(i, B)
Bs[i + 1] = fastGet();
REP(i, Q) {
ll x = fastGet();
ll *ita = lower_bound(As, As + A, x);
ll *itb = lower_bound(Bs, Bs + B, x);
ll ans = INF;
ll alis[2], blis[2];
alis[0] = *ita;
blis[0] = *itb;
alis[1] = ita[-1];
blis[1] = itb[-1];
REP(j, 2)
REP(k, 2) {
ll a = alis[j], b = blis[k];
ans = min(ans, abs(a - x) + abs(b - a));
ans = min(ans, abs(b - x) + abs(b - a));
}
fastPut(ans);
putchar_unlocked('\n');
}
return 0;
}
| /*
How to lambda
ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound of 2
1 2 2 2 3 3
^lb ^ub */
#include <cstdio>
#define BR "\n"
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define ALL(cont) begin(cont), end(cont)
#define AS_MOD(a, b) ((((a) % (b)) + (b)) % (b))
#define FEACH(it, cont) for (auto(it) = begin(cont); it != end(cont); ++it)
#define FEACHR(it, cont) for (auto(it) = rbegin(cont); it != rend(cont); ++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V = max(V, T)
using namespace std;
typedef long long ll;
typedef long double ld;
int A, B, Q;
ll As[100000 + 10];
ll Bs[100000 + 10];
ll INF = (ll)1000 * 1000 * 1000 * 1000;
ll min(ll a, ll b) { return a > b ? b : a; }
ll abs(ll a) { return a > 0 ? a : -a; }
ll *lower_bound(ll *a, ll *b, ll v) {
while (b > a + 1) {
ll *m = a + (b - a) / 2;
if (*m >= v) {
b = m;
} else {
a = m;
}
}
return b;
}
char buf[1 << 25];
int p = 0;
inline char my_get_char() { return buf[p++]; }
#define getchar_unlocked my_get_char
ll fastGet() {
ll ret = 0;
char c = getchar_unlocked();
// skipping
while (c < '0' || c > '9')
c = getchar_unlocked();
do {
ret = (ret << 3) + (ret << 1);
ret += (c - '0');
c = getchar_unlocked();
} while (c >= '0' && c <= '9');
return ret;
}
void fastPut(ll v) {
char s[256];
int p = 0;
do {
s[p++] = (v % 10) + '0';
v /= 10;
} while (v > 0);
while (p--)
putchar_unlocked(s[p]);
}
int main() {
fread(buf, 1, sizeof(buf), stdin);
A = fastGet();
B = fastGet();
Q = fastGet();
As[0] = -INF;
Bs[0] = -INF;
As[A + 1] = INF;
Bs[B + 1] = INF;
REP(i, A)
As[i + 1] = fastGet();
REP(i, B)
Bs[i + 1] = fastGet();
REP(i, Q) {
ll x = fastGet();
ll *ita = lower_bound(As, As + A, x);
ll *itb = lower_bound(Bs, Bs + B, x);
ll ans = INF;
ll alis[2], blis[2];
alis[0] = *ita;
blis[0] = *itb;
alis[1] = ita[-1];
blis[1] = itb[-1];
REP(j, 2)
REP(k, 2) {
ll a = alis[j], b = blis[k];
ans = min(ans, abs(a - x) + abs(b - a));
ans = min(ans, abs(b - x) + abs(b - a));
}
fastPut(ans);
putchar_unlocked('\n');
}
return 0;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p03112 | C++ | Runtime Error | // ref: https://drken1215.hatenablog.com/entry/2019/02/24/230900
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;
//---
template <typename T> inline void print(const T &rhs) {
std::cout << " = " << rhs << std::endl;
}
template <typename T> inline void print(const std::vector<T> &rhs) {
std::cout << " = [ ";
for (uint i = 0; i < rhs.size(); ++i) {
std::cout << rhs[i] << ' ';
}
std::cout << "]" << std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>> &rhs) {
std::cout << " = " << std::endl;
std::cout << "[[ ";
for (uint p = 0; p < rhs.size(); ++p) {
if (p != 0) {
std::cout << " [ ";
}
for (uint q = 0; q < rhs[p].size(); ++q) {
std::cout << rhs[p][q] << ' ';
}
if (p != rhs.size() - 1) {
std::cout << "]" << std::endl;
}
}
std::cout << "]]" << std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR, TL>> &rhs) {
std::cout << " = [";
uint i = 0;
for (; i < rhs.size() - 1; ++i) {
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "], ";
}
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "]]"
<< endl;
}
#define printn(var) \
{ \
printf("%s", #var); \
print(var); \
}
#define printn_all(var) \
{ \
printf("%s(%d): ", __func__, __LINE__); \
printf("%s", #var); \
print(var); \
}
//---
//*
int64 nearest(const vector<int64> &v, int64 dst) {
int l_idx = 0;
int r_idx = v.size() - 1;
if (dst <= v[l_idx]) {
return v[l_idx];
}
if (dst >= v[r_idx]) {
return v[r_idx];
}
while (r_idx - l_idx > 1) { // binary search
int n_idx = (l_idx + r_idx) / 2;
if (dst < v[n_idx]) {
r_idx = n_idx;
} else {
l_idx = n_idx;
}
}
return (abs(v[l_idx] - dst) < abs(v[r_idx] - dst)
? v[l_idx]
: v[r_idx]); // return neatest index with value.
}
//*/
/*
pair<int,int> arg_nearest(const vector<int64>& v, int64 dst){
int l_idx = 0;
int r_idx = v.size() - 1;
if(dst <= v[l_idx]){ return make_pair(l_idx, l_idx); }
if(dst >= v[r_idx]){ return make_pair(r_idx, r_idx); }
while(r_idx - l_idx > 1){ // binary search
int n_idx = (l_idx + r_idx)/2;
if(dst < v[n_idx]){ r_idx = n_idx;
} else { l_idx = n_idx; }
}
return make_pair(l_idx, r_idx);
}
//*/
/*
template<typename T>
T nearest_down(const vector<T>& v, const T& value){
uint idx = std::upper_bound(v.begin(), v.end(), value) - v.begin();
return v[ (idx!=0 ? idx-1:0) ];
}
template<typename T>
T nearest_up (const vector<T>& v, const T& value){
uint idx = std::lower_bound(v.begin(), v.end(), value) - v.begin();
return v[ (idx!=v.size() ? idx:v.size()-1) ];
}
template<typename T>
T nearest(const vector<T>& v, const T& value){
T val1 = nearest_down(v, value);
T val2 = nearest_up (v, value);
return (abs(val1-value)<abs(val2-value) ? val1 : val2);
}
*/
template <typename T> uint argnearest_down(const vector<T> &v, const T &value) {
uint idx = upper_bound(v.begin(), v.end(), value) - v.begin();
return (idx != 0 ? idx - 1 : 0);
}
template <typename T> uint argnearest_up(const vector<T> &v, const T &value) {
uint idx = lower_bound(v.begin(), v.end(), value) - v.begin();
return (idx != v.size() ? idx : v.size() - 1);
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int A, B, Q;
cin >> A >> B >> Q;
vector<int64> vS(A);
for (int i = 0; i < A; ++i) {
cin >> vS[i];
} // sort(vS.begin(), vS.end());
vector<int64> vT(B);
for (int i = 0; i < B; ++i) {
cin >> vT[i];
} // sort(vT.begin(), vT.end());
vector<int64> vX(Q);
for (int i = 0; i < Q; ++i) {
cin >> vX[i];
}
for (int i = 0; i < Q; ++i) {
int idxL, idxR;
int64 val1, val2;
int64 tmp1 = 0ll, tmp2 = 0ll;
idxL = argnearest_down(vS, vX[i]);
idxR = argnearest_up(vS, vX[i]);
val1 = nearest(vT, vS[idxL]);
val2 = nearest(vT, vS[idxR]);
tmp1 += abs(vS[idxL] - vX[i]);
tmp1 += abs(val1 - vS[idxL]);
tmp2 += abs(vS[idxR] - vX[i]);
tmp2 += abs(val2 - vS[idxR]);
tmp1 = min(tmp1, tmp2);
int64 tmp3 = 0ll, tmp4 = 0ll;
idxL = argnearest_down(vS, vX[i]);
idxR = argnearest_up(vS, vX[i]);
val1 = nearest(vS, vT[idxL]);
val2 = nearest(vS, vT[idxR]);
tmp3 += abs(vT[idxL] - vX[i]);
tmp3 += abs(val1 - vT[idxL]);
tmp4 += abs(vT[idxR] - vX[i]);
tmp4 += abs(val2 - vT[idxR]);
tmp3 = min(tmp3, tmp4);
cout << min(tmp1, tmp3) << endl;
}
return 0;
}
| // ref: https://drken1215.hatenablog.com/entry/2019/02/24/230900
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;
//---
template <typename T> inline void print(const T &rhs) {
std::cout << " = " << rhs << std::endl;
}
template <typename T> inline void print(const std::vector<T> &rhs) {
std::cout << " = [ ";
for (uint i = 0; i < rhs.size(); ++i) {
std::cout << rhs[i] << ' ';
}
std::cout << "]" << std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>> &rhs) {
std::cout << " = " << std::endl;
std::cout << "[[ ";
for (uint p = 0; p < rhs.size(); ++p) {
if (p != 0) {
std::cout << " [ ";
}
for (uint q = 0; q < rhs[p].size(); ++q) {
std::cout << rhs[p][q] << ' ';
}
if (p != rhs.size() - 1) {
std::cout << "]" << std::endl;
}
}
std::cout << "]]" << std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR, TL>> &rhs) {
std::cout << " = [";
uint i = 0;
for (; i < rhs.size() - 1; ++i) {
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "], ";
}
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "]]"
<< endl;
}
#define printn(var) \
{ \
printf("%s", #var); \
print(var); \
}
#define printn_all(var) \
{ \
printf("%s(%d): ", __func__, __LINE__); \
printf("%s", #var); \
print(var); \
}
//---
//*
int64 nearest(const vector<int64> &v, int64 dst) {
int l_idx = 0;
int r_idx = v.size() - 1;
if (dst <= v[l_idx]) {
return v[l_idx];
}
if (dst >= v[r_idx]) {
return v[r_idx];
}
while (r_idx - l_idx > 1) { // binary search
int n_idx = (l_idx + r_idx) / 2;
if (dst < v[n_idx]) {
r_idx = n_idx;
} else {
l_idx = n_idx;
}
}
return (abs(v[l_idx] - dst) < abs(v[r_idx] - dst)
? v[l_idx]
: v[r_idx]); // return neatest index with value.
}
//*/
/*
pair<int,int> arg_nearest(const vector<int64>& v, int64 dst){
int l_idx = 0;
int r_idx = v.size() - 1;
if(dst <= v[l_idx]){ return make_pair(l_idx, l_idx); }
if(dst >= v[r_idx]){ return make_pair(r_idx, r_idx); }
while(r_idx - l_idx > 1){ // binary search
int n_idx = (l_idx + r_idx)/2;
if(dst < v[n_idx]){ r_idx = n_idx;
} else { l_idx = n_idx; }
}
return make_pair(l_idx, r_idx);
}
//*/
/*
template<typename T>
T nearest_down(const vector<T>& v, const T& value){
uint idx = std::upper_bound(v.begin(), v.end(), value) - v.begin();
return v[ (idx!=0 ? idx-1:0) ];
}
template<typename T>
T nearest_up (const vector<T>& v, const T& value){
uint idx = std::lower_bound(v.begin(), v.end(), value) - v.begin();
return v[ (idx!=v.size() ? idx:v.size()-1) ];
}
template<typename T>
T nearest(const vector<T>& v, const T& value){
T val1 = nearest_down(v, value);
T val2 = nearest_up (v, value);
return (abs(val1-value)<abs(val2-value) ? val1 : val2);
}
*/
template <typename T> uint argnearest_down(const vector<T> &v, const T &value) {
uint idx = upper_bound(v.begin(), v.end(), value) - v.begin();
return (idx != 0 ? idx - 1 : 0);
}
template <typename T> uint argnearest_up(const vector<T> &v, const T &value) {
uint idx = lower_bound(v.begin(), v.end(), value) - v.begin();
return (idx != v.size() ? idx : v.size() - 1);
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int A, B, Q;
cin >> A >> B >> Q;
vector<int64> vS(A);
for (int i = 0; i < A; ++i) {
cin >> vS[i];
} // sort(vS.begin(), vS.end());
vector<int64> vT(B);
for (int i = 0; i < B; ++i) {
cin >> vT[i];
} // sort(vT.begin(), vT.end());
vector<int64> vX(Q);
for (int i = 0; i < Q; ++i) {
cin >> vX[i];
}
for (int i = 0; i < Q; ++i) {
int idxL, idxR;
int64 val1, val2;
int64 tmp1 = 0ll, tmp2 = 0ll;
idxL = argnearest_down(vS, vX[i]);
idxR = argnearest_up(vS, vX[i]);
val1 = nearest(vT, vS[idxL]);
val2 = nearest(vT, vS[idxR]);
tmp1 += abs(vS[idxL] - vX[i]);
tmp1 += abs(val1 - vS[idxL]);
tmp2 += abs(vS[idxR] - vX[i]);
tmp2 += abs(val2 - vS[idxR]);
tmp1 = min(tmp1, tmp2);
int64 tmp3 = 0ll, tmp4 = 0ll;
idxL = argnearest_down(vT, vX[i]);
idxR = argnearest_up(vT, vX[i]);
val1 = nearest(vS, vT[idxL]);
val2 = nearest(vS, vT[idxR]);
tmp3 += abs(vT[idxL] - vX[i]);
tmp3 += abs(val1 - vT[idxL]);
tmp4 += abs(vT[idxR] - vX[i]);
tmp4 += abs(val2 - vT[idxR]);
tmp3 = min(tmp3, tmp4);
cout << min(tmp1, tmp3) << endl;
}
return 0;
}
| replace | 164 | 166 | 164 | 166 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<long long> s(A);
vector<long long> t(B);
vector<long long> x(Q);
for (auto i = 0; i < A; ++i) {
cin >> s[i];
}
for (auto i = 0; i < B; ++i) {
cin >> t[i];
}
for (auto i = 0; i < Q; ++i) {
cin >> x[i];
}
auto search = [](vector<long long> list, long long start, long long &west,
long long &east) {
auto last = list.size() - 1;
if (start < list[0]) {
west = -1;
east = list[0];
return;
}
if (start > list[last]) {
west = list[last];
east = -1;
return;
}
auto iter = lower_bound(list.begin(), list.end(), start);
west = *(iter - 1);
east = *iter;
};
for (auto i = 0; i < Q; ++i) {
long long sWest, sEast, tWest, tEast;
auto start = x[i];
search(s, start, sWest, sEast);
search(t, start, tWest, tEast);
long long len = 1e11;
if (sWest >= 0) {
if (tWest >= 0) {
len = min(len, start - min(sWest, tWest));
}
if (tEast >= 0) {
len = min(len, tEast - sWest + min(tEast - start, start - sWest));
}
}
if (sEast >= 0) {
if (tWest >= 0) {
len = min(len, sEast - tWest + min(sEast - start, start - tWest));
}
if (tEast >= 0) {
len = min(len, max(sEast, tEast) - start);
}
}
cout << len << endl;
}
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<long long> s(A);
vector<long long> t(B);
vector<long long> x(Q);
for (auto i = 0; i < A; ++i) {
cin >> s[i];
}
for (auto i = 0; i < B; ++i) {
cin >> t[i];
}
for (auto i = 0; i < Q; ++i) {
cin >> x[i];
}
auto search = [](vector<long long> &list, long long start, long long &west,
long long &east) {
auto last = list.size() - 1;
if (start < list[0]) {
west = -1;
east = list[0];
return;
}
if (start > list[last]) {
west = list[last];
east = -1;
return;
}
auto iter = lower_bound(list.begin(), list.end(), start);
west = *(iter - 1);
east = *iter;
};
for (auto i = 0; i < Q; ++i) {
long long sWest, sEast, tWest, tEast;
auto start = x[i];
search(s, start, sWest, sEast);
search(t, start, tWest, tEast);
long long len = 1e11;
if (sWest >= 0) {
if (tWest >= 0) {
len = min(len, start - min(sWest, tWest));
}
if (tEast >= 0) {
len = min(len, tEast - sWest + min(tEast - start, start - sWest));
}
}
if (sEast >= 0) {
if (tWest >= 0) {
len = min(len, sEast - tWest + min(sEast - start, start - tWest));
}
if (tEast >= 0) {
len = min(len, max(sEast, tEast) - start);
}
}
cout << len << endl;
}
return 0;
}
| replace | 28 | 29 | 28 | 29 | TLE | |
p03112 | C++ | Time Limit Exceeded | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
const int maxn = 100000 + 5;
#define INF 1e14
int a, b, q;
long long s[maxn], t[maxn];
vector<long long> ss, tt;
int main() {
while (scanf("%d%d%d", &a, &b, &q) == 3) {
ss.clear();
tt.clear();
for (int i = 0; i < a; i++)
scanf("%lld", &s[i]);
for (int i = 0; i < b; i++)
scanf("%lld", &t[i]);
long long pos;
while (q--) {
scanf("%lld", &pos);
int right_s = lower_bound(s, s + a, pos) - s;
if (right_s < a)
ss.push_back(s[right_s]);
int left_s = right_s - 1;
if (left_s >= 0)
ss.push_back(s[left_s]);
int right_t = lower_bound(t, t + b, pos) - t;
if (right_t < b)
tt.push_back(t[right_t]);
int left_t = right_t - 1;
if (left_t >= 0)
tt.push_back(t[left_t]);
long long ans = INF;
for (unsigned i = 0; i < ss.size(); i++) {
for (unsigned j = 0; j < tt.size(); j++) {
long long t1 = abs(pos - ss[i]) + abs(ss[i] - tt[j]),
t2 = abs(pos - tt[j]) + abs(tt[j] - ss[i]);
ans = min(ans, min(t1, t2));
}
}
printf("%lld\n", ans);
}
}
return 0;
} | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
const int maxn = 100000 + 5;
#define INF 1e14
int a, b, q;
long long s[maxn], t[maxn];
vector<long long> ss, tt;
int main() {
while (scanf("%d%d%d", &a, &b, &q) == 3) {
ss.clear();
tt.clear();
for (int i = 0; i < a; i++)
scanf("%lld", &s[i]);
for (int i = 0; i < b; i++)
scanf("%lld", &t[i]);
long long pos;
while (q--) {
scanf("%lld", &pos);
ss.clear();
tt.clear();
int right_s = lower_bound(s, s + a, pos) - s;
if (right_s < a)
ss.push_back(s[right_s]);
int left_s = right_s - 1;
if (left_s >= 0)
ss.push_back(s[left_s]);
int right_t = lower_bound(t, t + b, pos) - t;
if (right_t < b)
tt.push_back(t[right_t]);
int left_t = right_t - 1;
if (left_t >= 0)
tt.push_back(t[left_t]);
long long ans = INF;
for (unsigned i = 0; i < ss.size(); i++) {
for (unsigned j = 0; j < tt.size(); j++) {
long long t1 = abs(pos - ss[i]) + abs(ss[i] - tt[j]),
t2 = abs(pos - tt[j]) + abs(tt[j] - ss[i]);
ans = min(ans, min(t1, t2));
}
}
printf("%lld\n", ans);
}
}
return 0;
} | insert | 22 | 22 | 22 | 24 | TLE | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll A, B, Q;
cin >> A >> B >> Q;
std::vector<ll> s(A), t(B), x(Q);
std::for_each(s.begin(), s.end(), [](auto &x) { cin >> x; });
std::for_each(t.begin(), t.end(), [](auto &x) { cin >> x; });
std::for_each(x.begin(), x.end(), [](auto &x) { cin >> x; });
std::pair<ll, ll> s_nearest, t_nearest;
for (const auto &e : x) {
const auto si = std::find_if(s.cbegin(), s.cend(),
[&e](const auto i) { return i > e; });
const auto ti = std::find_if(t.cbegin(), t.cend(),
[&e](const auto i) { return i > e; });
if (si == s.begin()) {
s_nearest = std::make_pair(-1ll << 60, *s.cbegin());
} else if (si == s.cend()) {
s_nearest = std::make_pair(*(s.cend() - 1), 1ll << 60);
} else {
s_nearest = std::make_pair(*(si - 1), *si);
}
if (ti == t.begin()) {
t_nearest = std::make_pair(-1ll << 60, *t.cbegin());
} else if (ti == t.cend()) {
t_nearest = std::make_pair(*(t.cend() - 1), 1ll << 60);
} else {
t_nearest = std::make_pair(*(ti - 1), *ti);
}
ll ans = std::numeric_limits<ll>::max();
ans = std::min(ans, std::abs(s_nearest.first - e) +
std::abs(t_nearest.first - s_nearest.first));
ans = std::min(ans, std::abs(s_nearest.first - e) +
std::abs(t_nearest.second - s_nearest.first));
ans = std::min(ans, std::abs(s_nearest.second - e) +
std::abs(t_nearest.first - s_nearest.second));
ans = std::min(ans, std::abs(s_nearest.second - e) +
std::abs(t_nearest.second - s_nearest.second));
ans = std::min(ans, std::abs(t_nearest.first - e) +
std::abs(s_nearest.first - t_nearest.first));
ans = std::min(ans, std::abs(t_nearest.first - e) +
std::abs(s_nearest.second - t_nearest.first));
ans = std::min(ans, std::abs(t_nearest.second - e) +
std::abs(s_nearest.first - t_nearest.second));
ans = std::min(ans, std::abs(t_nearest.second - e) +
std::abs(s_nearest.second - t_nearest.second));
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll A, B, Q;
cin >> A >> B >> Q;
std::vector<ll> s(A), t(B), x(Q);
std::for_each(s.begin(), s.end(), [](auto &x) { cin >> x; });
std::for_each(t.begin(), t.end(), [](auto &x) { cin >> x; });
std::for_each(x.begin(), x.end(), [](auto &x) { cin >> x; });
std::pair<ll, ll> s_nearest, t_nearest;
for (const auto &e : x) {
const auto si = std::lower_bound(s.cbegin(), s.cend(), e);
const auto ti = std::lower_bound(t.cbegin(), t.cend(), e);
if (si == s.begin()) {
s_nearest = std::make_pair(-1ll << 60, *s.cbegin());
} else if (si == s.cend()) {
s_nearest = std::make_pair(*(s.cend() - 1), 1ll << 60);
} else {
s_nearest = std::make_pair(*(si - 1), *si);
}
if (ti == t.begin()) {
t_nearest = std::make_pair(-1ll << 60, *t.cbegin());
} else if (ti == t.cend()) {
t_nearest = std::make_pair(*(t.cend() - 1), 1ll << 60);
} else {
t_nearest = std::make_pair(*(ti - 1), *ti);
}
ll ans = std::numeric_limits<ll>::max();
ans = std::min(ans, std::abs(s_nearest.first - e) +
std::abs(t_nearest.first - s_nearest.first));
ans = std::min(ans, std::abs(s_nearest.first - e) +
std::abs(t_nearest.second - s_nearest.first));
ans = std::min(ans, std::abs(s_nearest.second - e) +
std::abs(t_nearest.first - s_nearest.second));
ans = std::min(ans, std::abs(s_nearest.second - e) +
std::abs(t_nearest.second - s_nearest.second));
ans = std::min(ans, std::abs(t_nearest.first - e) +
std::abs(s_nearest.first - t_nearest.first));
ans = std::min(ans, std::abs(t_nearest.first - e) +
std::abs(s_nearest.second - t_nearest.first));
ans = std::min(ans, std::abs(t_nearest.second - e) +
std::abs(s_nearest.first - t_nearest.second));
ans = std::min(ans, std::abs(t_nearest.second - e) +
std::abs(s_nearest.second - t_nearest.second));
cout << ans << endl;
}
return 0;
} | replace | 17 | 21 | 17 | 19 | TLE | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int A, B, Q;
vector<long long> s;
vector<long long> t;
vector<long long> x;
void chmin(long long &a, long long b) {
if (a > b)
a = b;
}
template <class T> int former(const vector<T> &v, T x) {
return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T> int latter(const vector<T> &v, T x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
const long long INF = 1LL << 58;
int main() {
cin >> A >> B >> Q;
s.resize(A);
t.resize(B);
x.resize(Q);
for (int i = 0; i < A; i++) {
cin >> s[i];
}
for (int i = 0; i < B; i++) {
cin >> t[i];
}
for (int i = 0; i < Q; i++) {
cin >> x[i];
}
s.push_back(INF);
s.push_back(-INF);
t.push_back(INF);
t.push_back(-INF);
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (int i = 0; i < Q; i++) {
long long pos = x[i];
long long res = INF;
for (int j = 0; j < 2; j++) {
long long first = (j ? s[former(s, pos)] : s[latter(s, pos)]);
for (int k = 0; k < 2; k++) {
long long second = (k ? t[former(t, first)] : t[latter(t, first)]);
chmin(res, abs(pos - first) + abs(first - second));
}
}
for (int j = 0; j < 2; j++) {
long long first = (j ? t[former(s, pos)] : t[latter(s, pos)]);
for (int k = 0; k < 2; k++) {
long long second = (k ? s[former(s, first)] : s[latter(s, first)]);
chmin(res, abs(pos - first) + abs(first - second));
}
}
cout << res << endl;
}
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int A, B, Q;
vector<long long> s;
vector<long long> t;
vector<long long> x;
void chmin(long long &a, long long b) {
if (a > b)
a = b;
}
template <class T> int former(const vector<T> &v, T x) {
return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T> int latter(const vector<T> &v, T x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
const long long INF = 1LL << 58;
int main() {
cin >> A >> B >> Q;
s.resize(A);
t.resize(B);
x.resize(Q);
for (int i = 0; i < A; i++) {
cin >> s[i];
}
for (int i = 0; i < B; i++) {
cin >> t[i];
}
for (int i = 0; i < Q; i++) {
cin >> x[i];
}
s.push_back(INF);
s.push_back(-INF);
t.push_back(INF);
t.push_back(-INF);
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (int i = 0; i < Q; i++) {
long long pos = x[i];
long long res = INF;
for (int j = 0; j < 2; j++) {
long long first = (j ? s[former(s, pos)] : s[latter(s, pos)]);
for (int k = 0; k < 2; k++) {
long long second = (k ? t[former(t, first)] : t[latter(t, first)]);
chmin(res, abs(pos - first) + abs(first - second));
}
}
for (int j = 0; j < 2; j++) {
long long first = (j ? t[former(t, pos)] : t[latter(t, pos)]);
for (int k = 0; k < 2; k++) {
long long second = (k ? s[former(s, first)] : s[latter(s, first)]);
chmin(res, abs(pos - first) + abs(first - second));
}
}
cout << res << endl;
}
}
| replace | 53 | 54 | 53 | 54 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(), a.end()), a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int, vector<int>, greater<int>>
#define PriP \
priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a) (a).begin(), (a).end()
#define elif else if
int low(V<int> a, int b) {
decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
int upp(V<int> a, int b) {
decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
template <class T> void cou(vector<vector<T>> a) {
int b = a.size();
int c = a[0].size();
fo(i, b) {
fo(j, c) {
cout << a[i][j];
if (j == c - 1)
cout << endl;
else
cout << ' ';
}
}
}
int wari(int a, int b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
int souwa(int a) { return a * (a + 1) / 2; }
int gcm(int a, int b) {
if (a % b == 0)
return b;
return gcm(b, a % b);
}
bool prime(int a) {
if (a < 2)
return false;
else if (a == 2)
return true;
else if (a % 2 == 0)
return false;
for (int i = 3; i <= sqrt(a) + 1; i += 2) {
if (a % i == 0)
return false;
}
return true;
}
struct Union {
vector<int> par;
Union(int a) { par = vector<int>(a, -1); }
int find(int a) {
if (par[a] < 0)
return a;
else
return par[a] = find(par[a]);
}
bool same(int a, int b) { return find(a) == find(b); }
int Size(int a) { return -par[find(a)]; }
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
if (Size(b) > Size(a))
swap<int>(a, b);
par[a] += par[b];
par[b] = a;
}
};
int ketas(int a) {
string b = to_string(a);
int c = 0;
fo(i, keta(a)) { c += b[i] - '0'; }
return c;
}
bool fe(int a, int b) {
a %= 10;
b %= 10;
if (a == 0)
a = 10;
if (b == 0)
b = 10;
if (a > b)
return true;
else
return false;
}
int INF = 1000000007;
struct edge {
int s, t, d;
};
V<int> mojisyu(string a) {
V<int> b(26, 0);
fo(i, a.sz) { b[a[i] - 'a']++; }
return b;
}
int wa2(int a) {
if (a % 2 == 1)
return a / 2;
return a / 2 - 1;
}
/*signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}
?*/
int nCr(int n, int r) {
if (n < r)
return 0;
int a = 1;
r = min(r, n - r);
for (int i = n; i > n - r; i--) {
a *= i;
a /= n - i + 1;
}
return a;
}
/*void sea(int x,int y){
if(x<0||a<=x||y<0||b<=y||c[x][y]=='#')
return;
if(d[x][y])
return;
d[x][y]++;
sea(x+1,y);
sea(x-1,y);
sea(x,y+1);
sea(x,y-1);
}*/
int kaijou(int a) {
int b = 1;
fo(i, a) b *= i + 1;
return b;
}
int nPr(int a, int b) {
if (a < b)
return 0;
if (b == 0)
return 1;
int c = 1;
for (int i = a; i > a - b; i--) {
c *= i;
c %= INF;
}
return c;
}
int modinv(int a, int m) {
int b = m, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int lcm(int a, int b) {
int c = modinv(gcm(a, b), INF);
return ((a * c) % INF) * (b % INF) % INF;
}
int MOD = INF;
int fac[1000010], finv[1000010], inv[1000010];
// テーブルを作る前処理
// 先にCOMinit()で前処理をする
// ABC145D
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 1000010; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
int COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool naka(int a, int b, V<V<char>> c) {
return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz);
}
V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0},
{-1, -1}, {1, 1}, {1, -1}, {-1, -1}};
int inf = 1000000000000000007;
/*
signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}*/
V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
// 最短経路の表 a(全部INFで初期化)
// 縦横 x,y
// 迷路 f
// スタートsx,sy
// ゴールgx,gy
// 文字はgから使おうね
/*int bfs_haba(){
Q<P<int,int>> b;
a[sx][sy]=0;
b.push({sx,sy});
while(!b.empty()){
P<int,int> c=b.front();
b.pop();
if(c.fi==gx&&c.se==gy){
break;
}
fo(i,4){
int d=c.fi+mawari4[i].fi;
int e=c.se+mawari4[i].se;
if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){
b.push({d,e});
a[d][e]=1+a[c.fi][c.se];
}
}
}
return a[gx][gy];
}*/
V<int> onajibubun(string a) {
V<int> b(a.sz);
for (int i = 1, j = 0; i < a.sz; i++) {
if (i + b[i - j] < j + b[j])
b[i] = b[i - j];
else {
int c = max<int>(0, j + b[j] - i);
while (i + c < a.sz && a[c] == a[i + c])
c++;
b[i] = c;
j = i;
}
}
b[0] = a.sz;
return b;
}
// 各頂点ごとにどこに辺が出てるかの表がc
// 各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する
// aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ
V<int> color(205);
bool nibu_hantei(int a, int b, V<V<int>> c) {
color[a] = b;
fo(i, c[a].sz) {
if (b == color[c[a][i]])
return false;
if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c))
return false;
}
return true;
}
// aは頂点数
// nibu_hanteiの上にcolorを用意する
// 各頂点ごとにどこに辺が出てるかの表がc
bool renketujanai_nibu_hantei(int a, V<V<int>> c) {
fo(i, a) {
if (color[i] == 0) {
if (!nibu_hantei(i, 1, c))
return false;
}
}
return true;
}
signed main() {
int a, b, c;
cin >> a >> b >> c;
V<int> d(a), e(b), f(c);
fo(i, a) { cin >> d[i]; }
fo(i, b) { cin >> e[i]; }
fo(i, c) { cin >> f[i]; }
d.pb(inf);
d.pb(-inf);
e.pb(inf);
e.pb(-inf);
Sort(d);
Sort(e);
fo(i, c) {
int g = low(d, f[i]);
int h = low(e, f[i]);
cout << min(min(max(d[g], e[h]) - f[i], f[i] - min(d[g - 1], e[h - 1])),
min(min(2 * (d[g] - f[i]) + f[i] - e[h - 1],
2 * (f[i] - d[g - 1]) + e[h] - f[i]),
min(e[h] - f[i] + e[h] - d[g - 1],
f[i] - e[h - 1] + d[g] - e[h - 1])))
<< endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(), a.end()), a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int, vector<int>, greater<int>>
#define PriP \
priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a) (a).begin(), (a).end()
#define elif else if
int low(V<int> a, int b) {
decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
int upp(V<int> a, int b) {
decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
template <class T> void cou(vector<vector<T>> a) {
int b = a.size();
int c = a[0].size();
fo(i, b) {
fo(j, c) {
cout << a[i][j];
if (j == c - 1)
cout << endl;
else
cout << ' ';
}
}
}
int wari(int a, int b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
int souwa(int a) { return a * (a + 1) / 2; }
int gcm(int a, int b) {
if (a % b == 0)
return b;
return gcm(b, a % b);
}
bool prime(int a) {
if (a < 2)
return false;
else if (a == 2)
return true;
else if (a % 2 == 0)
return false;
for (int i = 3; i <= sqrt(a) + 1; i += 2) {
if (a % i == 0)
return false;
}
return true;
}
struct Union {
vector<int> par;
Union(int a) { par = vector<int>(a, -1); }
int find(int a) {
if (par[a] < 0)
return a;
else
return par[a] = find(par[a]);
}
bool same(int a, int b) { return find(a) == find(b); }
int Size(int a) { return -par[find(a)]; }
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
if (Size(b) > Size(a))
swap<int>(a, b);
par[a] += par[b];
par[b] = a;
}
};
int ketas(int a) {
string b = to_string(a);
int c = 0;
fo(i, keta(a)) { c += b[i] - '0'; }
return c;
}
bool fe(int a, int b) {
a %= 10;
b %= 10;
if (a == 0)
a = 10;
if (b == 0)
b = 10;
if (a > b)
return true;
else
return false;
}
int INF = 1000000007;
struct edge {
int s, t, d;
};
V<int> mojisyu(string a) {
V<int> b(26, 0);
fo(i, a.sz) { b[a[i] - 'a']++; }
return b;
}
int wa2(int a) {
if (a % 2 == 1)
return a / 2;
return a / 2 - 1;
}
/*signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}
?*/
int nCr(int n, int r) {
if (n < r)
return 0;
int a = 1;
r = min(r, n - r);
for (int i = n; i > n - r; i--) {
a *= i;
a /= n - i + 1;
}
return a;
}
/*void sea(int x,int y){
if(x<0||a<=x||y<0||b<=y||c[x][y]=='#')
return;
if(d[x][y])
return;
d[x][y]++;
sea(x+1,y);
sea(x-1,y);
sea(x,y+1);
sea(x,y-1);
}*/
int kaijou(int a) {
int b = 1;
fo(i, a) b *= i + 1;
return b;
}
int nPr(int a, int b) {
if (a < b)
return 0;
if (b == 0)
return 1;
int c = 1;
for (int i = a; i > a - b; i--) {
c *= i;
c %= INF;
}
return c;
}
int modinv(int a, int m) {
int b = m, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int lcm(int a, int b) {
int c = modinv(gcm(a, b), INF);
return ((a * c) % INF) * (b % INF) % INF;
}
int MOD = INF;
int fac[1000010], finv[1000010], inv[1000010];
// テーブルを作る前処理
// 先にCOMinit()で前処理をする
// ABC145D
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 1000010; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
int COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool naka(int a, int b, V<V<char>> c) {
return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz);
}
V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0},
{-1, -1}, {1, 1}, {1, -1}, {-1, -1}};
int inf = 1000000000000000007;
/*
signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}*/
V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
// 最短経路の表 a(全部INFで初期化)
// 縦横 x,y
// 迷路 f
// スタートsx,sy
// ゴールgx,gy
// 文字はgから使おうね
/*int bfs_haba(){
Q<P<int,int>> b;
a[sx][sy]=0;
b.push({sx,sy});
while(!b.empty()){
P<int,int> c=b.front();
b.pop();
if(c.fi==gx&&c.se==gy){
break;
}
fo(i,4){
int d=c.fi+mawari4[i].fi;
int e=c.se+mawari4[i].se;
if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){
b.push({d,e});
a[d][e]=1+a[c.fi][c.se];
}
}
}
return a[gx][gy];
}*/
V<int> onajibubun(string a) {
V<int> b(a.sz);
for (int i = 1, j = 0; i < a.sz; i++) {
if (i + b[i - j] < j + b[j])
b[i] = b[i - j];
else {
int c = max<int>(0, j + b[j] - i);
while (i + c < a.sz && a[c] == a[i + c])
c++;
b[i] = c;
j = i;
}
}
b[0] = a.sz;
return b;
}
// 各頂点ごとにどこに辺が出てるかの表がc
// 各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する
// aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ
V<int> color(205);
bool nibu_hantei(int a, int b, V<V<int>> c) {
color[a] = b;
fo(i, c[a].sz) {
if (b == color[c[a][i]])
return false;
if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c))
return false;
}
return true;
}
// aは頂点数
// nibu_hanteiの上にcolorを用意する
// 各頂点ごとにどこに辺が出てるかの表がc
bool renketujanai_nibu_hantei(int a, V<V<int>> c) {
fo(i, a) {
if (color[i] == 0) {
if (!nibu_hantei(i, 1, c))
return false;
}
}
return true;
}
signed main() {
int a, b, c;
cin >> a >> b >> c;
V<int> d(a), e(b), f(c);
fo(i, a) { cin >> d[i]; }
fo(i, b) { cin >> e[i]; }
fo(i, c) { cin >> f[i]; }
d.pb(inf);
d.pb(-inf);
e.pb(inf);
e.pb(-inf);
Sort(d);
Sort(e);
fo(i, c) {
auto g1 = lower_bound(d.bgn, d.en, f[i]);
auto h1 = lower_bound(e.bgn, e.en, f[i]);
int ga = *g1;
int ha = *h1;
int gb = *(g1 - 1);
int hb = *(h1 - 1);
cout << min(min(max(ga, ha) - f[i], f[i] - min(gb, hb)),
min(min(2 * (ga - f[i]) + f[i] - hb,
2 * (f[i] - gb) + ha - f[i]),
min(ha - f[i] + ha - gb, f[i] - hb + ga - hb)))
<< endl;
}
} | replace | 376 | 383 | 376 | 386 | TLE | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name, num) vector<ll> name((num), 0);
#define op(i) cout << (i) << endl;
#define ip(i) cin >> (i);
#define opN cout << "No" << endl;
#define opY cout << "Yes" << endl;
#define opP cout << "Possible" << endl;
#define opI cout << "Impossible" << endl;
#define mat(name, fnum, snum) \
; \
vector<vector<ll>> name((fnum), vector<ll>((snum), 0));
#define debugP \
int debug_point; \
cin >> debug_point;
const ll MOD = 1e9 + 7;
template <typename T> void putv(vector<T> &V) {
// cout << "The elements in the vector are: " << endl;
for (auto x : V)
cout << x << " ";
cout << endl;
}
ll pown(ll fi, ll se) {
ll ans = 1;
rep(i, se) { ans *= fi; }
return ans;
}
template <class T> vector<T> getv(ll n) {
vector<T> Vector_temp;
rep(i, n) {
T input;
cin >> input;
Vector_temp.emplace_back(input);
}
return Vector_temp;
}
ll gcd(ll c, ll b) {
while (1) {
if (c % b != 0) {
ll tmp = b;
b = c % b;
c = tmp;
} else {
return b;
}
}
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/
int main() {
ll a, b, q;
cin >> a >> b >> q;
vec(s, a + 2);
vec(t, b + 2);
vec(x, q);
repf(i, 1, a + 1) { cin >> s[i]; }
repf(i, 1, b + 1) { cin >> t[i]; }
s[0] = -10000000000;
s[a + 1] = 30000000000;
t[0] = -100000000000;
t[b + 1] = 300000000000;
rep(i, q) cin >> x[i];
rep(i, q) {
ll y[2];
ll z[2];
ll ans = LLONG_MAX;
y[0] = *lower_bound(&s[0], &s[b + 2], x[i]);
y[1] = *(lower_bound(&s[0], &s[b + 2], x[i]) - 1);
z[0] = *lower_bound(&t[0], &t[b + 2], x[i]);
z[1] = *(lower_bound(&t[0], &t[b + 2], x[i]) - 1);
rep(j, 2) {
rep(k, 2) {
ans = min(ans, abs(y[j] - x[i]) + abs(z[k] - y[j]));
ans = min(ans, abs(z[j] - x[i]) + abs(y[k] - z[j]));
}
}
op(ans);
}
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name, num) vector<ll> name((num), 0);
#define op(i) cout << (i) << endl;
#define ip(i) cin >> (i);
#define opN cout << "No" << endl;
#define opY cout << "Yes" << endl;
#define opP cout << "Possible" << endl;
#define opI cout << "Impossible" << endl;
#define mat(name, fnum, snum) \
; \
vector<vector<ll>> name((fnum), vector<ll>((snum), 0));
#define debugP \
int debug_point; \
cin >> debug_point;
const ll MOD = 1e9 + 7;
template <typename T> void putv(vector<T> &V) {
// cout << "The elements in the vector are: " << endl;
for (auto x : V)
cout << x << " ";
cout << endl;
}
ll pown(ll fi, ll se) {
ll ans = 1;
rep(i, se) { ans *= fi; }
return ans;
}
template <class T> vector<T> getv(ll n) {
vector<T> Vector_temp;
rep(i, n) {
T input;
cin >> input;
Vector_temp.emplace_back(input);
}
return Vector_temp;
}
ll gcd(ll c, ll b) {
while (1) {
if (c % b != 0) {
ll tmp = b;
b = c % b;
c = tmp;
} else {
return b;
}
}
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/
int main() {
ll a, b, q;
cin >> a >> b >> q;
vec(s, a + 2);
vec(t, b + 2);
vec(x, q);
repf(i, 1, a + 1) { cin >> s[i]; }
repf(i, 1, b + 1) { cin >> t[i]; }
s[0] = -10000000000;
s[a + 1] = 30000000000;
t[0] = -100000000000;
t[b + 1] = 300000000000;
rep(i, q) cin >> x[i];
rep(i, q) {
ll y[2];
ll z[2];
ll ans = LLONG_MAX;
y[0] = *lower_bound(&s[0], &s[a + 2], x[i]);
y[1] = *(lower_bound(&s[0], &s[a + 2], x[i]) - 1);
z[0] = *lower_bound(&t[0], &t[b + 2], x[i]);
z[1] = *(lower_bound(&t[0], &t[b + 2], x[i]) - 1);
rep(j, 2) {
rep(k, 2) {
ans = min(ans, abs(y[j] - x[i]) + abs(z[k] - y[j]));
ans = min(ans, abs(z[j] - x[i]) + abs(y[k] - z[j]));
}
}
op(ans);
}
return 0;
} | replace | 78 | 80 | 78 | 80 | 0 | |
p03112 | C++ | Runtime Error | // includes
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using namespace std;
// types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;
// solve
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
bool comp(const Pl &a, const Pl &b) { return a.first < b.first; }
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b, q;
cin >> a >> b >> q;
vector<ll> s(a), t(b);
rep(i, a) cin >> s[i];
rep(i, b) cin >> t[i];
rep(i, q) {
ll x;
cin >> x;
int ls = lower_bound(all(s), x) - s.begin() - 1;
int rs = ls + 1;
int lt = lower_bound(all(t), x) - t.begin() - 1;
int rt = lt + 1;
ll res = linf;
if (ls >= 0 && lt >= 0) {
res = min(res, x - min(s[ls], t[lt]));
}
if (ls >= 0 && rt < b) {
res = min(res, min((ll)2 * (x - s[ls]) + t[rt] - x,
(ll)2 * (t[rt] - x) + x - s[ls]));
}
if (rs < a && lt >= 0) {
res = min(res, min((ll)2 * (x - s[lt]) + t[rs] - x,
(ll)2 * (t[rs] - x) + x - s[lt]));
}
if (rs < a && rt < b) {
res = min(res, max(s[rs], t[rt]) - x);
}
cout << res << endl;
}
return 0;
}
| // includes
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using namespace std;
// types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;
// solve
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
bool comp(const Pl &a, const Pl &b) { return a.first < b.first; }
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b, q;
cin >> a >> b >> q;
vector<ll> s(a), t(b);
rep(i, a) cin >> s[i];
rep(i, b) cin >> t[i];
rep(i, q) {
ll x;
cin >> x;
int ls = lower_bound(all(s), x) - s.begin() - 1;
int rs = ls + 1;
int lt = lower_bound(all(t), x) - t.begin() - 1;
int rt = lt + 1;
ll res = linf;
if (ls >= 0 && lt >= 0) {
res = min(res, x - min(s[ls], t[lt]));
}
if (ls >= 0 && rt < b) {
res = min(res, min((ll)2 * (x - s[ls]) + t[rt] - x,
(ll)2 * (t[rt] - x) + x - s[ls]));
}
if (rs < a && lt >= 0) {
res = min(res, min((ll)2 * (x - t[lt]) + s[rs] - x,
(ll)2 * (s[rs] - x) + x - t[lt]));
}
if (rs < a && rt < b) {
res = min(res, max(s[rs], t[rt]) - x);
}
cout << res << endl;
}
return 0;
}
| replace | 89 | 91 | 89 | 91 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9 + 7;
#define endl "\n"
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) \
partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) \
INV(src); \
partial_sum((src).begin(), (src).end(), (dst).begin(), lambda); \
INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) { return a + b; })
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) { return a + b; })
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) { return a + b; })
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) \
ASC(v); \
v.erase(unique(v.begin(), v.end()), v.end())
template <typename T> void debug(T t) { cerr << t << endl; }
template <typename T, typename... Args> void debug(T t, Args... args) {
cerr << t << " ";
debug(args...);
}
template <typename T> void out(T t) { cout << t << endl; }
template <typename T, typename... Args> void out(T t, Args... args) {
cout << t << " ";
out(args...);
}
pll binsearch(ll x, vll v, ll n = 20) {
ll lb = 0, ub = v.size() - 1;
REP(i, n) {
ll md = (lb + ub) / 2;
if (x < v[md]) {
ub = md;
} else {
lb = md;
}
}
return {lb, ub};
}
void solve() {
ll A, B, Q;
cin >> A >> B >> Q;
vll S(A), T(B);
for (auto &a : S)
cin >> a;
for (auto &a : T)
cin >> a;
S.insert(S.begin() + 0, -1e17);
S.push_back(1e17);
T.insert(T.begin() + 0, -1e17);
T.push_back(1e17);
vll ans(Q);
REP(i, Q) {
ll x, s1, s2, t1, t2;
cin >> x;
pll ps = binsearch(x, S);
pll pt = binsearch(x, T);
s1 = S[ps.first];
s2 = S[ps.first + 1];
t1 = T[pt.first];
t2 = T[pt.first + 1];
vll a = {abs(x - s1) + abs(s1 - t1), abs(x - s1) + abs(s1 - t2),
abs(x - t1) + abs(t1 - s1), abs(x - t1) + abs(t1 - s2),
abs(x - s2) + abs(s2 - t1), abs(x - s2) + abs(s2 - t2),
abs(x - t2) + abs(t2 - s1), abs(x - t2) + abs(t2 - s2)};
ASC(a);
ans[i] = a[0];
}
REP(i, Q) out(ans[i]);
}
int main() {
fast_io;
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9 + 7;
#define endl "\n"
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) \
partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) \
INV(src); \
partial_sum((src).begin(), (src).end(), (dst).begin(), lambda); \
INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) { return a + b; })
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) { return a + b; })
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) { return a + b; })
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) \
ASC(v); \
v.erase(unique(v.begin(), v.end()), v.end())
template <typename T> void debug(T t) { cerr << t << endl; }
template <typename T, typename... Args> void debug(T t, Args... args) {
cerr << t << " ";
debug(args...);
}
template <typename T> void out(T t) { cout << t << endl; }
template <typename T, typename... Args> void out(T t, Args... args) {
cout << t << " ";
out(args...);
}
pll binsearch(ll x, vll &v, ll n = 20) {
ll lb = 0, ub = v.size() - 1;
REP(i, n) {
ll md = (lb + ub) / 2;
if (x < v[md]) {
ub = md;
} else {
lb = md;
}
}
return {lb, ub};
}
void solve() {
ll A, B, Q;
cin >> A >> B >> Q;
vll S(A), T(B);
for (auto &a : S)
cin >> a;
for (auto &a : T)
cin >> a;
S.insert(S.begin() + 0, -1e17);
S.push_back(1e17);
T.insert(T.begin() + 0, -1e17);
T.push_back(1e17);
vll ans(Q);
REP(i, Q) {
ll x, s1, s2, t1, t2;
cin >> x;
pll ps = binsearch(x, S);
pll pt = binsearch(x, T);
s1 = S[ps.first];
s2 = S[ps.first + 1];
t1 = T[pt.first];
t2 = T[pt.first + 1];
vll a = {abs(x - s1) + abs(s1 - t1), abs(x - s1) + abs(s1 - t2),
abs(x - t1) + abs(t1 - s1), abs(x - t1) + abs(t1 - s2),
abs(x - s2) + abs(s2 - t1), abs(x - s2) + abs(s2 - t2),
abs(x - t2) + abs(t2 - s1), abs(x - t2) + abs(t2 - s2)};
ASC(a);
ans[i] = a[0];
}
REP(i, Q) out(ans[i]);
}
int main() {
fast_io;
solve();
return 0;
}
| replace | 46 | 47 | 46 | 47 | TLE | |
p03112 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
const ll inf = 1ll << 60;
int main() {
int a, b, q;
cin >> a >> b >> q;
vector<ll> s(a + 4);
s[0] = -inf - 1;
s[1] = -inf;
s[a + 2] = inf;
s[a + 3] = inf + 1;
vector<ll> t(b + 4);
t[0] = -inf - 1;
t[1] = -inf;
t[b + 2] = inf;
t[b + 3] = inf + 1;
for (int i = 2; i <= a + 1; i++)
cin >> s[i];
for (int i = 2; i <= b + 1; i++)
cin >> t[i];
vector<ll> x(q);
rep(i, q) cin >> x[i];
rep(i, q) {
ll a1 = *lower_bound(all(s), x[i]);
ll b1 = *prev(lower_bound(all(s), x[i]), 1);
ll c1 = *lower_bound(all(t), a1);
ll d1 = *prev(lower_bound(all(t), a1), 1);
ll e1 = *lower_bound(all(t), b1);
ll f1 = *prev(lower_bound(all(t), b1), 1);
ll dist1 = inf;
chmin(dist1, abs(x[i] - a1) + abs(a1 - c1));
chmin(dist1, abs(x[i] - a1) + abs(a1 - d1));
chmin(dist1, abs(x[i] - b1) + abs(b1 - e1));
chmin(dist1, abs(x[i] - b1) + abs(b1 - f1));
ll a2 = *lower_bound(all(t), x[i]);
ll b2 = *prev(lower_bound(all(t), x[i]), 1);
ll c2 = *lower_bound(all(s), a2);
ll d2 = *prev(lower_bound(all(s), a2), 1);
ll e2 = *lower_bound(all(s), b2);
ll f2 = *prev(lower_bound(all(s), b2), 1);
ll dist2 = inf;
chmin(dist2, abs(x[i] - a2) + abs(a2 - c2));
chmin(dist2, abs(x[i] - a2) + abs(a2 - d2));
chmin(dist2, abs(x[i] - b2) + abs(b2 - e2));
chmin(dist2, abs(x[i] - b2) + abs(b2 - f2));
ll ans = min(dist1, dist2);
cout << ans << endl;
}
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
const ll inf = 1ll << 60;
int main() {
int a, b, q;
cin >> a >> b >> q;
vector<ll> s(a + 4);
s[0] = -inf - 1;
s[1] = -inf;
s[a + 2] = inf;
s[a + 3] = inf + 1;
vector<ll> t(b + 4);
t[0] = -inf - 1;
t[1] = -inf;
t[b + 2] = inf;
t[b + 3] = inf + 1;
for (int i = 2; i <= a + 1; i++)
cin >> s[i];
for (int i = 2; i <= b + 1; i++)
cin >> t[i];
vector<ll> x(q);
rep(i, q) cin >> x[i];
rep(i, q) {
ll a1 = *lower_bound(all(s), x[i]);
ll b1 = *prev(lower_bound(all(s), x[i]), 1);
ll c1 = *lower_bound(all(t), a1);
ll d1 = *prev(lower_bound(all(t), a1), 1);
ll e1 = *lower_bound(all(t), b1);
ll f1 = *prev(lower_bound(all(t), b1), 1);
ll dist1 = inf;
chmin(dist1, abs(x[i] - a1) + abs(a1 - c1));
chmin(dist1, abs(x[i] - a1) + abs(a1 - d1));
chmin(dist1, abs(x[i] - b1) + abs(b1 - e1));
chmin(dist1, abs(x[i] - b1) + abs(b1 - f1));
ll a2 = *lower_bound(all(t), x[i]);
ll b2 = *prev(lower_bound(all(t), x[i]), 1);
ll c2 = *lower_bound(all(s), a2);
ll d2 = *prev(lower_bound(all(s), a2), 1);
ll e2 = *lower_bound(all(s), b2);
ll f2 = *prev(lower_bound(all(s), b2), 1);
ll dist2 = inf;
chmin(dist2, abs(x[i] - a2) + abs(a2 - c2));
chmin(dist2, abs(x[i] - a2) + abs(a2 - d2));
chmin(dist2, abs(x[i] - b2) + abs(b2 - e2));
chmin(dist2, abs(x[i] - b2) + abs(b2 - f2));
ll ans = min(dist1, dist2);
cout << ans << endl;
}
} | replace | 0 | 1 | 0 | 1 | TLE | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
const ll INF = 1LL << 58;
int main() {
int a, b, q;
cin >> a >> b >> q;
vector<ll> s(a + 2), t(b + 2);
rep(i, a) cin >> s[i + 1];
rep(i, b) cin >> t[i + 1];
s[0] = t[0] = -INF;
s[a + 1] = t[a + 1] = INF;
sort(s.begin(), s.end());
sort(t.begin(), t.end());
vector<ll> p(q);
rep(i, q) {
ll x;
cin >> x;
ll ans = INF;
ll al = lower_bound(s.begin(), s.end(), x) - s.begin();
ll bl = lower_bound(t.begin(), t.end(), x) - t.begin();
ll af = upper_bound(s.begin(), s.end(), x) - s.begin() - 1;
ll bf = upper_bound(t.begin(), t.end(), x) - t.begin() - 1;
ans = min(ans, abs(s[af] - x) + abs(s[af] - t[bf]));
ans = min(ans, abs(s[af] - x) + abs(s[af] - t[bl]));
ans = min(ans, abs(s[al] - x) + abs(s[al] - t[bl]));
ans = min(ans, abs(s[al] - x) + abs(s[al] - t[bf]));
ans = min(ans, abs(t[bf] - x) + abs(s[af] - t[bf]));
ans = min(ans, abs(t[bf] - x) + abs(s[al] - t[bf]));
ans = min(ans, abs(t[bl] - x) + abs(s[af] - t[bl]));
ans = min(ans, abs(t[bl] - x) + abs(s[al] - t[bl]));
p[i] = ans;
}
rep(i, q) cout << p[i] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
const ll INF = 1LL << 58;
int main() {
int a, b, q;
cin >> a >> b >> q;
vector<ll> s(a + 2), t(b + 2);
rep(i, a) cin >> s[i + 1];
rep(i, b) cin >> t[i + 1];
s[0] = t[0] = -INF;
s[a + 1] = t[b + 1] = INF;
sort(s.begin(), s.end());
sort(t.begin(), t.end());
vector<ll> p(q);
rep(i, q) {
ll x;
cin >> x;
ll ans = INF;
ll al = lower_bound(s.begin(), s.end(), x) - s.begin();
ll bl = lower_bound(t.begin(), t.end(), x) - t.begin();
ll af = upper_bound(s.begin(), s.end(), x) - s.begin() - 1;
ll bf = upper_bound(t.begin(), t.end(), x) - t.begin() - 1;
ans = min(ans, abs(s[af] - x) + abs(s[af] - t[bf]));
ans = min(ans, abs(s[af] - x) + abs(s[af] - t[bl]));
ans = min(ans, abs(s[al] - x) + abs(s[al] - t[bl]));
ans = min(ans, abs(s[al] - x) + abs(s[al] - t[bf]));
ans = min(ans, abs(t[bf] - x) + abs(s[af] - t[bf]));
ans = min(ans, abs(t[bf] - x) + abs(s[al] - t[bf]));
ans = min(ans, abs(t[bl] - x) + abs(s[af] - t[bl]));
ans = min(ans, abs(t[bl] - x) + abs(s[al] - t[bl]));
p[i] = ans;
}
rep(i, q) cout << p[i] << endl;
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
long long calc(vector<long long> s, vector<long long> t, long long x) {
vector<long long>::iterator sRight =
lower_bound(s.begin(), s.end(), x); // x[i]以上が最初に現れる要素
vector<long long>::iterator sLeft;
if (sRight != s.begin()) {
sLeft = sRight - 1;
} else {
sLeft = sRight;
}
vector<long long>::iterator tRight = lower_bound(t.begin(), t.end(), x);
vector<long long>::iterator tLeft;
if (tRight != t.begin()) {
tLeft = tRight - 1;
} else {
tLeft = tRight;
}
long long tmp = min({
(long long)abs(*sRight - x) + (long long)abs(*sRight - *tRight),
(long long)abs(*sRight - x) + (long long)abs(*sRight - *tLeft),
(long long)abs(*sLeft - x) + (long long)abs(*sLeft - *tRight),
(long long)abs(*sLeft - x) + (long long)abs(*sLeft - *tLeft),
(long long)abs(*tRight - x) + (long long)abs(*tRight - *sRight),
(long long)abs(*tRight - x) + (long long)abs(*tRight - *sLeft),
(long long)abs(*tLeft - x) + (long long)abs(*tLeft - *sRight),
(long long)abs(*tLeft - x) + (long long)abs(*tLeft - *sLeft),
});
return tmp;
}
int main() {
long long A, B, Q;
cin >> A >> B >> Q;
vector<long long> s(A), t(B), x(Q);
vector<long long> ans(Q);
for (long long i = 0; i < s.size(); i++) {
cin >> s[i];
}
for (long long i = 0; i < t.size(); i++) {
cin >> t[i];
}
for (long long i = 0; i < x.size(); i++) {
cin >> x[i];
}
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (long long i = 0; i < ans.size(); i++) {
ans[i] = calc(s, t, x[i]);
}
for (long long i = 0; i < ans.size(); i++) {
std::cout << ans[i] << endl;
}
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
long long calc(vector<long long> &s, vector<long long> &t, long long x) {
vector<long long>::iterator sRight =
lower_bound(s.begin(), s.end(), x); // x[i]以上が最初に現れる要素
vector<long long>::iterator sLeft;
if (sRight != s.begin()) {
sLeft = sRight - 1;
} else {
sLeft = sRight;
}
vector<long long>::iterator tRight = lower_bound(t.begin(), t.end(), x);
vector<long long>::iterator tLeft;
if (tRight != t.begin()) {
tLeft = tRight - 1;
} else {
tLeft = tRight;
}
long long tmp = min({
(long long)abs(*sRight - x) + (long long)abs(*sRight - *tRight),
(long long)abs(*sRight - x) + (long long)abs(*sRight - *tLeft),
(long long)abs(*sLeft - x) + (long long)abs(*sLeft - *tRight),
(long long)abs(*sLeft - x) + (long long)abs(*sLeft - *tLeft),
(long long)abs(*tRight - x) + (long long)abs(*tRight - *sRight),
(long long)abs(*tRight - x) + (long long)abs(*tRight - *sLeft),
(long long)abs(*tLeft - x) + (long long)abs(*tLeft - *sRight),
(long long)abs(*tLeft - x) + (long long)abs(*tLeft - *sLeft),
});
return tmp;
}
int main() {
long long A, B, Q;
cin >> A >> B >> Q;
vector<long long> s(A), t(B), x(Q);
vector<long long> ans(Q);
for (long long i = 0; i < s.size(); i++) {
cin >> s[i];
}
for (long long i = 0; i < t.size(); i++) {
cin >> t[i];
}
for (long long i = 0; i < x.size(); i++) {
cin >> x[i];
}
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (long long i = 0; i < ans.size(); i++) {
ans[i] = calc(s, t, x[i]);
}
for (long long i = 0; i < ans.size(); i++) {
std::cout << ans[i] << endl;
}
} | replace | 7 | 8 | 7 | 8 | TLE | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const ll INF = ll(1e18);
ll hoge(ll cost, ll x, vector<ll> &v) {
auto it = lower_bound(v.begin(), v.end(), x);
int idx = it - v.begin();
ll cost3, cost4;
cost3 = INF, cost4 = INF;
if (idx < v.size()) {
cost4 = cost + abs(x - v[idx]);
}
if (idx > 0) {
cost3 = cost + abs(x - v[idx - 1]);
}
return min(cost3, cost4);
}
int main() {
cin.sync_with_stdio(false);
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A);
vector<ll> t(B);
rep(i, A) cin >> s[i];
rep(i, B) cin >> t[i];
vector<ll> ans;
rep(i, Q) {
ll x;
cin >> x;
auto it = lower_bound(s.begin(), s.end(), x);
int idx = it - s.begin();
ll cost1 = INF, cost2 = INF;
ll x1 = INF, x2 = INF;
if (idx < s.size()) {
cost2 = abs(x - s[idx]);
x2 = s[idx];
}
if (idx > 0) {
cost1 = abs(x - s[idx - 1]);
x1 = s[idx - 1];
}
ll cost = min(hoge(cost1, x1, t), hoge(cost2, x2, t));
it = lower_bound(t.begin(), t.end(), x);
cost1 = INF, cost2 = INF;
x1 = INF, x2 = INF;
if (idx < t.size()) {
cost2 = abs(x - t[idx]);
x2 = t[idx];
}
if (idx > 0) {
cost1 = abs(x - t[idx - 1]);
x1 = t[idx - 1];
}
ans.push_back(min({cost, hoge(cost1, x1, s), hoge(cost2, x2, s)}));
}
rep(i, Q) cout << ans[i] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const ll INF = ll(1e18);
ll hoge(ll cost, ll x, vector<ll> &v) {
auto it = lower_bound(v.begin(), v.end(), x);
int idx = it - v.begin();
ll cost3, cost4;
cost3 = INF, cost4 = INF;
if (idx < v.size()) {
cost4 = cost + abs(x - v[idx]);
}
if (idx > 0) {
cost3 = cost + abs(x - v[idx - 1]);
}
return min(cost3, cost4);
}
int main() {
cin.sync_with_stdio(false);
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> s(A);
vector<ll> t(B);
rep(i, A) cin >> s[i];
rep(i, B) cin >> t[i];
vector<ll> ans;
rep(i, Q) {
ll x;
cin >> x;
auto it = lower_bound(s.begin(), s.end(), x);
int idx = it - s.begin();
ll cost1 = INF, cost2 = INF;
ll x1 = INF, x2 = INF;
if (idx < s.size()) {
cost2 = abs(x - s[idx]);
x2 = s[idx];
}
if (idx > 0) {
cost1 = abs(x - s[idx - 1]);
x1 = s[idx - 1];
}
ll cost = min(hoge(cost1, x1, t), hoge(cost2, x2, t));
it = lower_bound(t.begin(), t.end(), x);
idx = it - t.begin();
cost1 = INF, cost2 = INF;
x1 = INF, x2 = INF;
if (idx < t.size()) {
cost2 = abs(x - t[idx]);
x2 = t[idx];
}
if (idx > 0) {
cost1 = abs(x - t[idx - 1]);
x1 = t[idx - 1];
}
ans.push_back(min({cost, hoge(cost1, x1, s), hoge(cost2, x2, s)}));
}
rep(i, Q) cout << ans[i] << endl;
return 0;
} | insert | 49 | 49 | 49 | 50 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge {
ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll query(ll pos, vi st) {
int a, b;
a = lower_bound(ALL(st), pos) - st.begin();
b = upper_bound(ALL(st), pos) - st.begin() - 1;
return min(abs(st[a] - pos), abs(st[b] - pos));
}
int main() {
int A, B, Q;
vi s, t, x;
cin >> A >> B >> Q;
s.resize(A + 1);
t.resize(B + 1);
x.resize(Q);
s[0] = -INF;
t[0] = -INF;
FOR(i, 1, A + 1)
cin >> s[i];
FOR(i, 1, B + 1)
cin >> t[i];
FOR(i, 0, Q)
cin >> x[i];
s.push_back(INF);
t.push_back(INF);
int idx;
ll ans;
REP(i, Q) {
ans = INF;
idx = lower_bound(ALL(s), x[i]) - s.begin();
chmin(ans, abs(x[i] - s[idx]) + query(s[idx], t));
idx = upper_bound(ALL(s), x[i]) - s.begin() - 1;
chmin(ans, abs(x[i] - s[idx]) + query(s[idx], t));
idx = lower_bound(ALL(t), x[i]) - t.begin();
chmin(ans, abs(x[i] - t[idx]) + query(t[idx], s));
idx = upper_bound(ALL(t), x[i]) - t.begin() - 1;
chmin(ans, abs(x[i] - t[idx]) + query(t[idx], s));
cout << ans << endl;
}
// system("pause");
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge {
ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll query(ll pos, vi &st) {
int a, b;
a = lower_bound(ALL(st), pos) - st.begin();
b = upper_bound(ALL(st), pos) - st.begin() - 1;
return min(abs(st[a] - pos), abs(st[b] - pos));
}
int main() {
int A, B, Q;
vi s, t, x;
cin >> A >> B >> Q;
s.resize(A + 1);
t.resize(B + 1);
x.resize(Q);
s[0] = -INF;
t[0] = -INF;
FOR(i, 1, A + 1)
cin >> s[i];
FOR(i, 1, B + 1)
cin >> t[i];
FOR(i, 0, Q)
cin >> x[i];
s.push_back(INF);
t.push_back(INF);
int idx;
ll ans;
REP(i, Q) {
ans = INF;
idx = lower_bound(ALL(s), x[i]) - s.begin();
chmin(ans, abs(x[i] - s[idx]) + query(s[idx], t));
idx = upper_bound(ALL(s), x[i]) - s.begin() - 1;
chmin(ans, abs(x[i] - s[idx]) + query(s[idx], t));
idx = lower_bound(ALL(t), x[i]) - t.begin();
chmin(ans, abs(x[i] - t[idx]) + query(t[idx], s));
idx = upper_bound(ALL(t), x[i]) - t.begin() - 1;
chmin(ans, abs(x[i] - t[idx]) + query(t[idx], s));
cout << ans << endl;
}
// system("pause");
} | replace | 31 | 32 | 31 | 32 | TLE | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
inline long long mod(long long n, long long m) { return (n % m + m) % m; }
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
int main() {
int a, b, q;
cin >> a >> b >> q;
vector<long long> s(a + 4);
vector<long long> t(b + 4);
s[0] = t[0] = -LINF / 2;
s[1] = t[1] = -LINF / 4;
rep(i, a) cin >> s[i + 2];
rep(i, b) cin >> t[i + 2];
s[a + 2] = t[a + 2] = LINF / 4;
s[a + 3] = t[a + 3] = LINF / 2;
while (q--) {
long long ans = LINF;
long long x;
cin >> x;
// 神社先
// 神社左
{
long long sh = *(lower_bound(all(s), x) - 1);
long long te = LINF;
// 寺左
te = *(lower_bound(all(t), sh) - 1);
ans = min(ans, abs(sh - x) + abs(sh - te));
// 寺右
te = *lower_bound(all(t), sh);
ans = min(ans, abs(sh - x) + abs(sh - te));
}
// 神社右
{
long long sh = *lower_bound(all(s), x);
long long te = LINF;
// 寺左
te = *(lower_bound(all(t), sh) - 1);
ans = min(ans, abs(sh - x) + abs(sh - te));
// 寺右
te = *lower_bound(all(t), sh);
ans = min(ans, abs(sh - x) + abs(sh - te));
}
// 寺先
// 寺左
{
long long te = *(lower_bound(all(t), x) - 1);
long long sh = LINF;
// 神社左
sh = *(lower_bound(all(s), te) - 1);
ans = min(ans, abs(te - x) + abs(sh - te));
// 神社右
sh = *lower_bound(all(s), te);
ans = min(ans, abs(te - x) + abs(sh - te));
}
// 寺右
{
long long te = *lower_bound(all(t), x);
long long sh = LINF;
// 神社左
sh = *(lower_bound(all(s), te) - 1);
ans = min(ans, abs(te - x) + abs(sh - te));
// 神社右
sh = *lower_bound(all(s), te);
ans = min(ans, abs(te - x) + abs(sh - te));
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
inline long long mod(long long n, long long m) { return (n % m + m) % m; }
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
int main() {
int a, b, q;
cin >> a >> b >> q;
vector<long long> s(a + 4);
vector<long long> t(b + 4);
s[0] = t[0] = -LINF / 2;
s[1] = t[1] = -LINF / 4;
rep(i, a) cin >> s[i + 2];
rep(i, b) cin >> t[i + 2];
s[a + 2] = t[b + 2] = LINF / 4;
s[a + 3] = t[b + 3] = LINF / 2;
while (q--) {
long long ans = LINF;
long long x;
cin >> x;
// 神社先
// 神社左
{
long long sh = *(lower_bound(all(s), x) - 1);
long long te = LINF;
// 寺左
te = *(lower_bound(all(t), sh) - 1);
ans = min(ans, abs(sh - x) + abs(sh - te));
// 寺右
te = *lower_bound(all(t), sh);
ans = min(ans, abs(sh - x) + abs(sh - te));
}
// 神社右
{
long long sh = *lower_bound(all(s), x);
long long te = LINF;
// 寺左
te = *(lower_bound(all(t), sh) - 1);
ans = min(ans, abs(sh - x) + abs(sh - te));
// 寺右
te = *lower_bound(all(t), sh);
ans = min(ans, abs(sh - x) + abs(sh - te));
}
// 寺先
// 寺左
{
long long te = *(lower_bound(all(t), x) - 1);
long long sh = LINF;
// 神社左
sh = *(lower_bound(all(s), te) - 1);
ans = min(ans, abs(te - x) + abs(sh - te));
// 神社右
sh = *lower_bound(all(s), te);
ans = min(ans, abs(te - x) + abs(sh - te));
}
// 寺右
{
long long te = *lower_bound(all(t), x);
long long sh = LINF;
// 神社左
sh = *(lower_bound(all(s), te) - 1);
ans = min(ans, abs(te - x) + abs(sh - te));
// 神社右
sh = *lower_bound(all(s), te);
ans = min(ans, abs(te - x) + abs(sh - te));
}
cout << ans << endl;
}
return 0;
}
| replace | 18 | 20 | 18 | 20 | 0 | |
p03112 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
const long long INF = 20000000001;
void Main() {
int a, b, q;
cin >> a >> b >> q;
vector<long long> s, t;
for (int i = 0; i < a; i++) {
long long tmp;
cin >> tmp;
s.push_back(tmp);
}
for (int i = 0; i < b; i++) {
long long tmp;
cin >> tmp;
t.push_back(tmp);
}
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (int i = 0; i < q; i++) {
long long x;
cin >> x;
int sl = -1, sr = s.size();
while (sr - sl > 1) {
int c = (sl + sr) / 2;
if (x <= s[c])
sr = c;
else
sl = c;
}
int tl = -1, tr = s.size();
while (tr - tl > 1) {
int c = (tl + tr) / 2;
if (x <= t[c])
tr = c;
else
tl = c;
}
long long ans = INF;
if (sr < s.size() && tr < t.size()) {
ans = min(ans, abs(s[sr] - x) + abs(t[tr] - s[sr]));
}
if (sr < s.size() && tr > 0) {
ans = min(ans, abs(s[sr] - x) + abs(t[tr - 1] - s[sr]));
}
if (sr > 0 && tr < t.size()) {
ans = min(ans, abs(s[sr - 1] - x) + abs(t[tr] - s[sr - 1]));
}
if (sr > 0 && tr > 0) {
ans = min(ans, abs(s[sr - 1] - x) + abs(t[tr - 1] - s[sr - 1]));
}
if (sr < s.size() && tr < t.size()) {
ans = min(ans, abs(t[tr] - x) + abs(s[sr] - t[tr]));
}
if (tr < t.size() && sr > 0) {
ans = min(ans, abs(t[tr] - x) + abs(s[sr - 1] - t[tr]));
}
if (tr > 0 && sr < s.size()) {
ans = min(ans, abs(t[tr - 1] - x) + abs(s[sr] - t[tr - 1]));
}
if (tr > 0 && sr > 0) {
ans = min(ans, abs(t[tr - 1] - x) + abs(s[sr - 1] - t[tr - 1]));
}
cout << ans << endl;
}
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
const long long INF = 20000000001;
void Main() {
int a, b, q;
cin >> a >> b >> q;
vector<long long> s, t;
for (int i = 0; i < a; i++) {
long long tmp;
cin >> tmp;
s.push_back(tmp);
}
for (int i = 0; i < b; i++) {
long long tmp;
cin >> tmp;
t.push_back(tmp);
}
sort(s.begin(), s.end());
sort(t.begin(), t.end());
for (int i = 0; i < q; i++) {
long long x;
cin >> x;
int sl = -1, sr = s.size();
while (sr - sl > 1) {
int c = (sl + sr) / 2;
if (x <= s[c])
sr = c;
else
sl = c;
}
int tl = -1, tr = t.size();
while (tr - tl > 1) {
int c = (tl + tr) / 2;
if (x <= t[c])
tr = c;
else
tl = c;
}
long long ans = INF;
if (sr < s.size() && tr < t.size()) {
ans = min(ans, abs(s[sr] - x) + abs(t[tr] - s[sr]));
}
if (sr < s.size() && tr > 0) {
ans = min(ans, abs(s[sr] - x) + abs(t[tr - 1] - s[sr]));
}
if (sr > 0 && tr < t.size()) {
ans = min(ans, abs(s[sr - 1] - x) + abs(t[tr] - s[sr - 1]));
}
if (sr > 0 && tr > 0) {
ans = min(ans, abs(s[sr - 1] - x) + abs(t[tr - 1] - s[sr - 1]));
}
if (sr < s.size() && tr < t.size()) {
ans = min(ans, abs(t[tr] - x) + abs(s[sr] - t[tr]));
}
if (tr < t.size() && sr > 0) {
ans = min(ans, abs(t[tr] - x) + abs(s[sr - 1] - t[tr]));
}
if (tr > 0 && sr < s.size()) {
ans = min(ans, abs(t[tr - 1] - x) + abs(s[sr] - t[tr - 1]));
}
if (tr > 0 && sr > 0) {
ans = min(ans, abs(t[tr - 1] - x) + abs(s[sr - 1] - t[tr - 1]));
}
cout << ans << endl;
}
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p03112 | Python | Runtime Error | from bisect import bisect_right
A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
x = int(input())
b, d = bisect_right(s, x), bisect_right(t, x)
res = INF
for S in [s[b - 1], s[b]]:
for T in [t[d - 1], t[d]]:
d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
res = min(res, d1, d2)
print(res)
| from bisect import bisect_right
A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
b, d = bisect_right(s, x), bisect_right(t, x)
res = INF
for S in [s[b - 1], s[b]]:
for T in [t[d - 1], t[d]]:
d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
res = min(res, d1, d2)
print(res)
| delete | 8 | 9 | 8 | 8 | EOFError: EOF when reading a line | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03112/Python/s591577203.py", line 8, in <module>
x = int(input())
EOFError: EOF when reading a line
|
p03112 | Python | Runtime Error | def p_d():
from bisect import bisect_right
A, B, Q = map(int, input().split())
INF = 10**9
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
ans = []
for _ in range(Q):
x = int(input())
b, d = bisect_right(s, x), bisect_right(t, x)
res = INF
for S in [s[b - 1], s[b]]:
for T in [t[d - 1], t[d]]:
d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
res = min((d1, d2, res))
ans.append(str(res))
print("\n".join(ans))
if __name__ == "__main__":
p_d()
| def p_d():
from bisect import bisect_right
A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
ans = []
for _ in range(Q):
x = int(input())
b, d = bisect_right(s, x), bisect_right(t, x)
res = INF
for S in [s[b - 1], s[b]]:
for T in [t[d - 1], t[d]]:
d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
res = min((d1, d2, res))
ans.append(str(res))
print("\n".join(ans))
if __name__ == "__main__":
p_d()
| replace | 4 | 5 | 4 | 5 | 0 | |
p03112 | Python | Runtime Error | import bisect
def solve(a_list, b_list, position):
# time O(log(A))
a_right_key = bisect.bisect_left(a_list, position)
a_left_key = a_right_key - 1
# time O(log(B))
b_right_key = bisect.bisect_left(b_list, position)
b_left_key = b_right_key - 1
a_left, a_right = a_list[a_left_key], a_list[a_right_key]
b_left, b_right = b_list[b_left_key], b_list[b_right_key]
ans = 10**20
for a_position in [a_left, a_right]:
for b_position in [b_left, b_right]:
distance1 = abs(position - a_position) + abs(a_position - b_position)
distance2 = abs(position - b_position) + abs(a_position - b_position)
ans = min(ans, distance1, distance2)
return ans
def main():
inf = 10**20
A, B, Q = map(int, input().split())
# time O(A)
a_list = [int(input()) for _ in range(A)]
a_list = [-inf] + a_list + [inf]
# time O(B)
b_list = [int(input()) for _ in range(A)]
b_list = [-inf] + b_list + [inf]
# time O(Q (log(A) + log(B))
for _ in range(Q):
position = int(input())
ans = solve(a_list, b_list, position)
print(ans)
if __name__ == "__main__":
main()
| import bisect
def solve(a_list, b_list, position):
# time O(log(A))
a_right_key = bisect.bisect_left(a_list, position)
a_left_key = a_right_key - 1
# time O(log(B))
b_right_key = bisect.bisect_left(b_list, position)
b_left_key = b_right_key - 1
a_left, a_right = a_list[a_left_key], a_list[a_right_key]
b_left, b_right = b_list[b_left_key], b_list[b_right_key]
ans = 10**20
for a_position in [a_left, a_right]:
for b_position in [b_left, b_right]:
distance1 = abs(position - a_position) + abs(a_position - b_position)
distance2 = abs(position - b_position) + abs(a_position - b_position)
ans = min(ans, distance1, distance2)
return ans
def main():
inf = 10**20
A, B, Q = map(int, input().split())
# time O(A)
a_list = [int(input()) for _ in range(A)]
a_list = [-inf] + a_list + [inf]
# time O(B)
b_list = [int(input()) for _ in range(B)]
b_list = [-inf] + b_list + [inf]
# time O(Q (log(A) + log(B))
for _ in range(Q):
position = int(input())
ans = solve(a_list, b_list, position)
print(ans)
if __name__ == "__main__":
main()
| replace | 31 | 32 | 31 | 32 | 0 | |
p03112 | C++ | Runtime Error | // dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define ff first
#define ss second
#define tm1 first.first
#define tm2 first.second
#define tm3 second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(), (v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define FER(i, a, b) for (int i = int(a); i < int(b); ++i)
#define IFR(i, a, b) for (int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> tri;
const int N = 1e5 + 20;
const ll inf = 1e16;
ll mm[N], ans[N];
vector<tri> vec;
ll LS[N], LT[N], RS[N], RT[N];
int main() {
fastio;
int s, t, q;
cin >> s >> t >> q;
vec.pb({{-inf, 1}, -1});
vec.pb({{-inf, 2}, -1});
vec.pb({{inf, 1}, -1});
vec.pb({{inf, 1}, -1});
vec.pb({{inf, 2}, -1});
FER(i, 0, s) {
ll k;
cin >> k;
vec.pb({{k, 1}, -1});
}
FER(i, 0, t) {
ll k;
cin >> k;
vec.pb({{k, 2}, -1});
}
FER(i, 0, q) {
ll k;
cin >> k;
vec.pb({{k, 3}, i});
}
sort(all(vec));
ii esta = {-2 * inf, -2 * inf};
FER(i, 0, sz(vec)) {
LS[i] = esta.ff;
LT[i] = esta.ss;
if (vec[i].tm2 == 1)
esta.ff = LS[i] = vec[i].tm1;
if (vec[i].tm2 == 2)
esta.ss = LT[i] = vec[i].tm1;
}
esta = {inf, inf};
IFR(i, sz(vec) - 1, 0) {
RS[i] = esta.ff;
RT[i] = esta.ss;
if (vec[i].tm2 == 1)
esta.ff = RS[i] = vec[i].tm1;
if (vec[i].tm2 == 2)
esta.ss = RT[i] = vec[i].tm1;
}
FER(i, 2, sz(vec) - 2) if (vec[i].tm3 != -1) {
LS[i] = abs(LS[i] - vec[i].tm1);
LT[i] = abs(LT[i] - vec[i].tm1);
RS[i] = abs(RS[i] - vec[i].tm1);
RT[i] = abs(RT[i] - vec[i].tm1);
ll val = min(max(LS[i], LT[i]), max(RS[i], RT[i]));
val = min(val, 2 * LT[i] + RS[i]);
val = min(val, 2 * RS[i] + LT[i]);
val = min(val, 2 * LS[i] + RT[i]);
val = min(val, 2 * RT[i] + LS[i]);
ans[vec[i].tm3] = val;
}
FER(i, 0, q) cout << ans[i] << endl;
return 0;
}
| // dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define ff first
#define ss second
#define tm1 first.first
#define tm2 first.second
#define tm3 second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(), (v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define FER(i, a, b) for (int i = int(a); i < int(b); ++i)
#define IFR(i, a, b) for (int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> tri;
const int N = 4e5 + 20;
const ll inf = 1e16;
ll mm[N], ans[N];
vector<tri> vec;
ll LS[N], LT[N], RS[N], RT[N];
int main() {
fastio;
int s, t, q;
cin >> s >> t >> q;
vec.pb({{-inf, 1}, -1});
vec.pb({{-inf, 2}, -1});
vec.pb({{inf, 1}, -1});
vec.pb({{inf, 1}, -1});
vec.pb({{inf, 2}, -1});
FER(i, 0, s) {
ll k;
cin >> k;
vec.pb({{k, 1}, -1});
}
FER(i, 0, t) {
ll k;
cin >> k;
vec.pb({{k, 2}, -1});
}
FER(i, 0, q) {
ll k;
cin >> k;
vec.pb({{k, 3}, i});
}
sort(all(vec));
ii esta = {-2 * inf, -2 * inf};
FER(i, 0, sz(vec)) {
LS[i] = esta.ff;
LT[i] = esta.ss;
if (vec[i].tm2 == 1)
esta.ff = LS[i] = vec[i].tm1;
if (vec[i].tm2 == 2)
esta.ss = LT[i] = vec[i].tm1;
}
esta = {inf, inf};
IFR(i, sz(vec) - 1, 0) {
RS[i] = esta.ff;
RT[i] = esta.ss;
if (vec[i].tm2 == 1)
esta.ff = RS[i] = vec[i].tm1;
if (vec[i].tm2 == 2)
esta.ss = RT[i] = vec[i].tm1;
}
FER(i, 2, sz(vec) - 2) if (vec[i].tm3 != -1) {
LS[i] = abs(LS[i] - vec[i].tm1);
LT[i] = abs(LT[i] - vec[i].tm1);
RS[i] = abs(RS[i] - vec[i].tm1);
RT[i] = abs(RT[i] - vec[i].tm1);
ll val = min(max(LS[i], LT[i]), max(RS[i], RT[i]));
val = min(val, 2 * LT[i] + RS[i]);
val = min(val, 2 * RS[i] + LT[i]);
val = min(val, 2 * LS[i] + RT[i]);
val = min(val, 2 * RT[i] + LS[i]);
ans[vec[i].tm3] = val;
}
FER(i, 0, q) cout << ans[i] << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, s, e) for (ll i = s; i >= e; i--)
#define reps(i, s, e) for (ll i = s; i <= e; i++)
#define inf 1e18
#define all(v) v.begin(), v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a + b - 1) / b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }
template <typename T> void vdebug(vector<T> v) {
for (auto vv : v) {
cout << vv << " ";
}
cout << endl;
}
template <typename T> void adebug(T arr[], ll n) {
rep(i, n) { cout << arr[i] << " "; }
cout << endl;
}
void ans(bool b) {
if (b)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool b) {
if (b)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
ll keta(ll num) {
ll k = 0;
while (num > 0) {
num /= 10;
k++;
}
return k;
}
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll a, b, q, tmp;
vector<ll> s, t, x;
cin >> a >> b >> q;
rep(i, a) {
cin >> tmp;
s.push_back(tmp);
}
rep(i, b) {
cin >> tmp;
t.push_back(tmp);
}
rep(i, q) {
cin >> tmp;
x.push_back(tmp);
}
vector<ll> scand;
vector<ll> tcand;
rep(i, q) {
ll sind = distance(s.begin(), lower_bound(all(s), x[i]));
ll tind = distance(t.begin(), lower_bound(all(t), x[i]));
if (sind == s.size()) {
sind = s.size() - 1;
scand.push_back(s[sind]);
} else if (sind == 0) {
scand.push_back(s[sind]);
} else {
scand.push_back(s[sind]);
scand.push_back(s[sind - 1]);
}
if (tind == t.size()) {
tind = t.size() - 1;
tcand.push_back(t[tind]);
} else if (tind == 0) {
tcand.push_back(t[tind]);
} else {
tcand.push_back(t[tind]);
tcand.push_back(t[tind - 1]);
}
ll res = inf;
rep(k, scand.size()) {
rep(j, tcand.size()) {
chmin(res, abs(x[i] - scand[k]) + abs(scand[k] - tcand[j]));
chmin(res, abs(x[i] - tcand[j]) + abs(tcand[j] - scand[k]));
}
}
cout << res << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, s, e) for (ll i = s; i >= e; i--)
#define reps(i, s, e) for (ll i = s; i <= e; i++)
#define inf 1e18
#define all(v) v.begin(), v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a + b - 1) / b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }
template <typename T> void vdebug(vector<T> v) {
for (auto vv : v) {
cout << vv << " ";
}
cout << endl;
}
template <typename T> void adebug(T arr[], ll n) {
rep(i, n) { cout << arr[i] << " "; }
cout << endl;
}
void ans(bool b) {
if (b)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool b) {
if (b)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
ll keta(ll num) {
ll k = 0;
while (num > 0) {
num /= 10;
k++;
}
return k;
}
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll a, b, q, tmp;
vector<ll> s, t, x;
cin >> a >> b >> q;
rep(i, a) {
cin >> tmp;
s.push_back(tmp);
}
rep(i, b) {
cin >> tmp;
t.push_back(tmp);
}
rep(i, q) {
cin >> tmp;
x.push_back(tmp);
}
vector<ll> scand;
vector<ll> tcand;
rep(i, q) {
ll sind = distance(s.begin(), lower_bound(all(s), x[i]));
ll tind = distance(t.begin(), lower_bound(all(t), x[i]));
if (sind == s.size()) {
sind = s.size() - 1;
scand.push_back(s[sind]);
} else if (sind == 0) {
scand.push_back(s[sind]);
} else {
scand.push_back(s[sind]);
scand.push_back(s[sind - 1]);
}
if (tind == t.size()) {
tind = t.size() - 1;
tcand.push_back(t[tind]);
} else if (tind == 0) {
tcand.push_back(t[tind]);
} else {
tcand.push_back(t[tind]);
tcand.push_back(t[tind - 1]);
}
ll res = inf;
rep(k, scand.size()) {
rep(j, tcand.size()) {
chmin(res, abs(x[i] - scand[k]) + abs(scand[k] - tcand[j]));
chmin(res, abs(x[i] - tcand[j]) + abs(tcand[j] - scand[k]));
}
}
cout << res << endl;
scand.clear();
tcand.clear();
}
return 0;
}
| insert | 121 | 121 | 121 | 123 | TLE | |
p03112 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long INF = 1LL << 60;
long long calc(vector<long long> s, vector<long long> t, long long x) {
long long answer = INF;
auto a_ = lower_bound(s.begin(), s.end(), x);
for (int i = 0; i < 2; i++) {
long long ax_ = *prev(a_);
if (i == 1) {
ax_ = *a_;
}
auto b_ = lower_bound(t.begin(), t.end(), ax_);
long long bxl_ = *prev(b_);
long long bxr_ = *b_;
if (0 < ax_ && 0 < bxl_) {
answer = min(answer, abs(ax_ - x) + abs(bxl_ - ax_));
}
if (0 < ax_ && 0 < bxr_) {
answer = min(answer, abs(ax_ - x) + abs(bxr_ - ax_));
}
}
return answer;
}
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<long long> s;
s.push_back(0);
for (int i = 1; i <= A; i++) {
long long s_;
cin >> s_;
s.push_back(s_);
}
s.push_back(INF);
vector<long long> t(B + 2);
t.push_back(0);
for (int i = 1; i <= B; i++) {
long long t_;
cin >> t_;
t.push_back(t_);
}
t.push_back(INF);
vector<long long> x(Q);
for (int i = 0; i < Q; i++) {
cin >> x[i];
}
for (int i = 0; i < Q; i++) {
long long answer = INF;
answer = min(calc(s, t, x[i]), calc(t, s, x[i]));
cout << answer << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
long long INF = 1LL << 60;
long long calc(vector<long long> &s, vector<long long> &t, long long x) {
long long answer = INF;
auto a_ = lower_bound(s.begin(), s.end(), x);
for (int i = 0; i < 2; i++) {
long long ax_ = *prev(a_);
if (i == 1) {
ax_ = *a_;
}
auto b_ = lower_bound(t.begin(), t.end(), ax_);
long long bxl_ = *prev(b_);
long long bxr_ = *b_;
if (0 < ax_ && 0 < bxl_) {
answer = min(answer, abs(ax_ - x) + abs(bxl_ - ax_));
}
if (0 < ax_ && 0 < bxr_) {
answer = min(answer, abs(ax_ - x) + abs(bxr_ - ax_));
}
}
return answer;
}
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<long long> s;
s.push_back(0);
for (int i = 1; i <= A; i++) {
long long s_;
cin >> s_;
s.push_back(s_);
}
s.push_back(INF);
vector<long long> t(B + 2);
t.push_back(0);
for (int i = 1; i <= B; i++) {
long long t_;
cin >> t_;
t.push_back(t_);
}
t.push_back(INF);
vector<long long> x(Q);
for (int i = 0; i < Q; i++) {
cin >> x[i];
}
for (int i = 0; i < Q; i++) {
long long answer = INF;
answer = min(calc(s, t, x[i]), calc(t, s, x[i]));
cout << answer << endl;
}
} | replace | 5 | 6 | 5 | 6 | TLE | |
p03112 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
typedef long long ll;
const ll INF = 1e15;
int main() {
int A, B, Q;
ll x;
cin >> A >> B >> Q;
ll s[A], t[B], ans[Q];
rep(i, A) cin >> s[i];
rep(i, B) cin >> t[i];
rep(i, Q) {
cin >> x;
int su = lower_bound(s, s + A, x) - s;
int tu = lower_bound(t, s + B, x) - t;
ll d[4];
rep(i, 4) d[i] = INF;
if (su < A && tu < B)
d[0] = max(s[su] - x, t[tu] - x);
if (su < A && tu > 0)
d[1] =
min(s[su] - x + 2 * (x - t[tu - 1]), 2 * (s[su] - x) + x - t[tu - 1]);
if (su > 0 && tu < B)
d[2] =
min(x - s[su - 1] + 2 * (t[tu] - x), 2 * (x - s[su - 1]) + t[tu] - x);
if (su > 0 && tu > 0)
d[3] = max(x - s[su - 1], x - t[tu - 1]);
sort(d, d + 4);
ans[i] = d[0];
}
rep(i, Q) cout << ans[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
typedef long long ll;
const ll INF = 1e15;
int main() {
int A, B, Q;
ll x;
cin >> A >> B >> Q;
ll s[A], t[B], ans[Q];
rep(i, A) cin >> s[i];
rep(i, B) cin >> t[i];
rep(i, Q) {
cin >> x;
int su = lower_bound(s, s + A, x) - s;
int tu = lower_bound(t, t + B, x) - t;
ll d[4];
rep(i, 4) d[i] = INF;
if (su < A && tu < B)
d[0] = max(s[su] - x, t[tu] - x);
if (su < A && tu > 0)
d[1] =
min(s[su] - x + 2 * (x - t[tu - 1]), 2 * (s[su] - x) + x - t[tu - 1]);
if (su > 0 && tu < B)
d[2] =
min(x - s[su - 1] + 2 * (t[tu] - x), 2 * (x - s[su - 1]) + t[tu] - x);
if (su > 0 && tu > 0)
d[3] = max(x - s[su - 1], x - t[tu - 1]);
sort(d, d + 4);
ans[i] = d[0];
}
rep(i, Q) cout << ans[i] << endl;
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03112 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <vector>
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return (true);
} else {
return (false);
}
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return (true);
} else {
return (false);
}
}
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Pll = pair<ll, ll>;
using Pull = pair<ull, ull>;
#define eb emplace_back
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)((n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = (int)((n)); i > 0; --i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define MOD (1e9 + 7)
#define INF (1e12)
#define MINF (-1e12)
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> vS(A + 2);
rep(i, A) { cin >> vS[i]; }
vector<ll> vT(B + 2);
rep(i, B) { cin >> vT[i]; }
vector<ll> vX(Q);
rep(i, Q) { cin >> vX[i]; }
// vS, vT に正負の無限遠の点を入れておく
vS[A] = MINF;
vS[A + 1] = INF;
vT[A] = MINF;
vT[A + 1] = INF;
sort(ALL(vS));
sort(ALL(vT));
for (auto &&it : vX) {
// 問itに対して、一番近い左右の寺2社2を求める
auto AB = upper_bound(ALL(vS), it);
ll sB = *AB;
ll sA = *prev(AB);
auto CD = upper_bound(ALL(vT), it);
ll tD = *CD;
ll tC = *prev(CD);
/* 上記4箇所の訪れ方の最小値を求める */
// 1. A -> C
ll ac = abs(sA - it) + abs(tC - sA);
// 2. A -> D
ll ad = abs(sA - it) + abs(tD - sA);
// 3. C -> A
ll ca = abs(tC - it) + abs(sA - tC);
// 4. D -> A
ll da = abs(tD - it) + abs(sA - tD);
// 5. B -> C
ll bc = abs(sB - it) + abs(tC - sB);
// 6. B -> D
ll bd = abs(sB - it) + abs(tD - sB);
// 7. C -> B
ll cb = abs(tC - it) + abs(sB - tC);
// 8. D -> B
ll db = abs(tD - it) + abs(sB - tD);
cout << min({ac, ad, ca, da, bc, bd, cb, db}) << endl;
}
return (0);
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <vector>
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return (true);
} else {
return (false);
}
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return (true);
} else {
return (false);
}
}
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Pll = pair<ll, ll>;
using Pull = pair<ull, ull>;
#define eb emplace_back
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)((n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = (int)((n)); i > 0; --i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define MOD (1e9 + 7)
#define INF (1e12)
#define MINF (-1e12)
int main() {
int A, B, Q;
cin >> A >> B >> Q;
vector<ll> vS(A + 2);
rep(i, A) { cin >> vS[i]; }
vector<ll> vT(B + 2);
rep(i, B) { cin >> vT[i]; }
vector<ll> vX(Q);
rep(i, Q) { cin >> vX[i]; }
// vS, vT に正負の無限遠の点を入れておく
vS[A] = MINF;
vS[A + 1] = INF;
vT[B] = MINF;
vT[B + 1] = INF;
sort(ALL(vS));
sort(ALL(vT));
for (auto &&it : vX) {
// 問itに対して、一番近い左右の寺2社2を求める
auto AB = upper_bound(ALL(vS), it);
ll sB = *AB;
ll sA = *prev(AB);
auto CD = upper_bound(ALL(vT), it);
ll tD = *CD;
ll tC = *prev(CD);
/* 上記4箇所の訪れ方の最小値を求める */
// 1. A -> C
ll ac = abs(sA - it) + abs(tC - sA);
// 2. A -> D
ll ad = abs(sA - it) + abs(tD - sA);
// 3. C -> A
ll ca = abs(tC - it) + abs(sA - tC);
// 4. D -> A
ll da = abs(tD - it) + abs(sA - tD);
// 5. B -> C
ll bc = abs(sB - it) + abs(tC - sB);
// 6. B -> D
ll bd = abs(sB - it) + abs(tD - sB);
// 7. C -> B
ll cb = abs(tC - it) + abs(sB - tC);
// 8. D -> B
ll db = abs(tD - it) + abs(sB - tD);
cout << min({ac, ad, ca, da, bc, bd, cb, db}) << endl;
}
return (0);
}
| replace | 68 | 70 | 68 | 70 | 0 | |
p03113 | Python | Runtime Error | def solve(n, k, aaa):
buf = []
prev_last = -1
for t in range(k + 1):
ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
others = set(range(1, n + 1)) - {prev_last, mi}
buf.extend(others)
if t == k:
aaa[mi] += 1
else:
buf.append(mi)
for i in range(n):
if i + 1 != prev_last:
aaa[i] -= 1
if aaa[i] < 0:
print(-1)
return
prev_last = mi
print(len(buf))
print(*buf)
n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)
| def solve(n, k, aaa):
buf = []
prev_last = -1
for t in range(k + 1):
ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
others = set(range(1, n + 1)) - {prev_last, mi}
buf.extend(others)
buf.append(mi)
# print(buf)
for i in range(n):
if i + 1 != prev_last:
aaa[i] -= 1
if aaa[i] < 0:
print(-1)
return
prev_last = mi
print(len(buf))
print(*buf)
n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)
| replace | 8 | 12 | 8 | 10 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03113/Python/s607630341.py", line 29, in <module>
solve(n, k, aaa)
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03113/Python/s607630341.py", line 10, in solve
aaa[mi] += 1
IndexError: list index out of range
|
p03113 | C++ | Runtime Error | // #define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>
using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;
template <class T = usize> class rep {
const T f, l;
public:
class itr {
friend rep;
T i;
constexpr itr(T x) noexcept : i(x) {}
public:
void operator++() noexcept { ++i; }
constexpr T operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
constexpr itr begin() const noexcept { return itr(f); }
constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
const T f, l;
public:
class itr {
friend revrep;
T i;
constexpr itr(T x) noexcept : i(x) {}
public:
void operator++() noexcept { --i; }
constexpr T operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
constexpr itr begin() const noexcept { return itr(l - 1); }
constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
return a <= b ? b - a : a - b;
}
#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
#include <utility>
int main() {
usize n, k;
::std::cin >> n >> k;
::std::vector<usize> a(n), rem(n);
for (auto &e : a) {
::std::cin >> e;
}
for (const auto i : rep<>(0, n)) {
if (a[i] < k + 1) {
rem[i] = k + 1 - a[i];
}
}
if ((k + 1) / 2 < *::std::max_element(rem.cbegin(), rem.cend())) {
::std::cout << "-1" << ::std::endl;
return 0;
}
if (k < ::std::accumulate(rem.cbegin(), rem.cend(), static_cast<usize>(0))) {
::std::cout << "-1" << ::std::endl;
return 0;
}
::std::vector<::std::pair<usize, usize>> rr(n);
for (const auto i : rep<>(0, n)) {
rr[i] = {rem[i], i};
}
::std::sort(rr.rbegin(), rr.rend());
::std::vector<usize> rs;
for (const auto i : rep<>(0, n)) {
for (const auto j : rep<>(0, rr[i].first)) {
rs.emplace_back(rr[i].second);
}
}
while (rs.size() < k) {
rs.emplace_back(rr.back().second);
}
const usize os = k % 2 ? k : k - 1;
::std::vector<usize> joints(k);
for (const auto i : rep<>(0, k)) {
if (i * 2 < k) {
joints[i * 2] = rs[i];
} else {
joints[i * 2 - os] = rs[i];
}
}
joints.push_back(n);
::std::vector<usize> ans;
for (const auto v : rep<>(0, n)) {
if (v != joints.front()) {
ans.emplace_back(v);
}
}
for (const auto i : rep<>(0, k)) {
ans.emplace_back(joints[i]);
for (const auto v : rep<>(0, n)) {
if (v != joints[i] && v != joints[i + 1]) {
ans.emplace_back(v);
}
}
}
const usize q = ans.size();
assert(q == (n - 1) * k + n);
::std::cout << q << ::std::endl;
for (const auto i : rep<>(0, q)) {
::std::cout << ans[i] + 1 << " \n"[i + 1 == q];
}
return 0;
}
| // #define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>
using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;
template <class T = usize> class rep {
const T f, l;
public:
class itr {
friend rep;
T i;
constexpr itr(T x) noexcept : i(x) {}
public:
void operator++() noexcept { ++i; }
constexpr T operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
constexpr itr begin() const noexcept { return itr(f); }
constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
const T f, l;
public:
class itr {
friend revrep;
T i;
constexpr itr(T x) noexcept : i(x) {}
public:
void operator++() noexcept { --i; }
constexpr T operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
constexpr itr begin() const noexcept { return itr(l - 1); }
constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
return a <= b ? b - a : a - b;
}
#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
#include <utility>
int main() {
usize n, k;
::std::cin >> n >> k;
::std::vector<usize> a(n), rem(n);
for (auto &e : a) {
::std::cin >> e;
}
for (const auto i : rep<>(0, n)) {
if (a[i] < k + 1) {
rem[i] = k + 1 - a[i];
}
}
if ((k + 1) / 2 < *::std::max_element(rem.cbegin(), rem.cend())) {
::std::cout << "-1" << ::std::endl;
return 0;
}
if (k < ::std::accumulate(rem.cbegin(), rem.cend(), static_cast<usize>(0))) {
::std::cout << "-1" << ::std::endl;
return 0;
}
::std::vector<::std::pair<usize, usize>> rr(n);
for (const auto i : rep<>(0, n)) {
rr[i] = {rem[i], i};
}
::std::sort(rr.rbegin(), rr.rend());
::std::vector<usize> rs;
for (const auto i : rep<>(0, n)) {
for (const auto j : rep<>(0, rr[i].first)) {
rs.emplace_back(rr[i].second);
}
}
while (rs.size() < k) {
rs.emplace_back(rr.back().second);
}
const usize os = k % 2 ? k : k - 1;
::std::vector<usize> joints(k);
for (const auto i : rep<>(0, k)) {
if (i * 2 < k) {
joints[i * 2] = rs[i];
} else {
joints[i * 2 - os] = rs[i];
}
}
joints.push_back(n);
::std::vector<usize> ans;
for (const auto v : rep<>(0, n)) {
if (v != joints.front()) {
ans.emplace_back(v);
}
}
for (const auto i : rep<>(0, k)) {
ans.emplace_back(joints[i]);
for (const auto v : rep<>(0, n)) {
if (v != joints[i] && v != joints[i + 1]) {
ans.emplace_back(v);
}
}
}
const usize q = ans.size();
// assert(q == (n - 1) * k + n);
::std::cout << q << ::std::endl;
for (const auto i : rep<>(0, q)) {
::std::cout << ans[i] + 1 << " \n"[i + 1 == q];
}
return 0;
}
| replace | 150 | 151 | 150 | 151 | 0 | |
p03113 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for (int i = 0; i < n; i++)
const int inf9 = 1e9;
const lint inf18 = 1e18;
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T = string, class U = char>
int character_count(T text, U character) {
int ans = 0;
for (U i : text) {
ans += (i == character);
}
return ans;
}
lint power(lint base, lint exponent, lint module) {
if (exponent % 2) {
return power(base, exponent - 1, module) * base % module;
} else if (exponent) {
lint root_ans = power(base, exponent / 2, module);
return root_ans * root_ans % module;
} else {
return 1;
}
}
struct position {
double y, x;
};
position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
double euclidean(position first, position second) {
return sqrt((second.x - first.x) * (second.x - first.x) +
(second.y - first.y) * (second.y - first.y));
}
double euclidean(double first, double second) {
return sqrt(first * first + second * second);
}
template <class T, class U> string to_string(pair<T, U> x) {
return to_string(x.first) + "," + to_string(x.second);
}
string to_string(string x) { return x; }
template <class itr> void array_output(itr start, itr goal) {
string ans;
for (auto i = start; i != goal; i++)
ans += to_string(*i) + " ";
if (!ans.empty())
ans.pop_back();
cout << ans << endl;
}
template <class itr> void cins(itr first, itr last) {
for (auto i = first; i != last; i++) {
cin >> (*i);
}
}
template <class T> T gcd(T a, T b) {
if (a && b) {
return gcd(min(a, b), max(a, b) % min(a, b));
} else {
return a;
}
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
struct combination {
vector<lint> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2, mod);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
lint P(int n, int r) {
if (r < 0 || n < r)
return 0;
return (fact[n] * inv[n - r] % mod);
}
lint C(int p, int q) {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
template <class itr> bool next_sequence(itr first, itr last, int max_bound) {
itr now = last;
while (now != first) {
now--;
(*now)++;
if ((*now) == max_bound) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
template <class itr, class itr2>
bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2) {
itr now = last;
itr2 now2 = last2;
while (now != first) {
now--, now2--;
(*now)++;
if ((*now) == (*now2)) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
inline int at(lint i, int j) { return (i >> j) & 1; }
int main() {
int N, K;
cin >> N >> K;
int a[N];
cins(a, a + N);
int a_copy[N];
for (int i = 0; i < N; i++) {
a_copy[i] = a[i];
a[i] = max(0, K + 1 - a[i]);
}
vector<int> pardon{-1};
for (int i = 0; i < K; i++) {
int max_pos = !pardon.back();
for (int j = 0; j < N; j++) {
if (a[j] > a[max_pos] && max_pos != pardon.back()) {
max_pos = j;
}
}
pardon.push_back(max_pos);
a[max_pos] = max(a[max_pos] - 1, 0);
}
if (accumulate(a, a + N, 0)) {
cout << -1 << endl;
return 0;
}
// array_output(all(pardon));
vector<int> ans;
for (int i = 0; i < K; i++) {
for (int j = 0; j < N; j++) {
if (pardon[i] != j && pardon[i + 1] != j) {
ans.push_back(j + 1);
}
}
ans.push_back(pardon[i + 1] + 1);
}
for (int j = 0; j < N; j++) {
if (pardon[K] != j) {
ans.push_back(j + 1);
}
}
int cnt[N];
fill(cnt, cnt + N, 0);
for (int i : ans) {
cnt[i - 1]++;
}
for (int i = 0; i < N; i++) {
assert(cnt[i] <= a_copy[i]);
}
cout << ans.size() << endl;
array_output(all(ans));
}
| #include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for (int i = 0; i < n; i++)
const int inf9 = 1e9;
const lint inf18 = 1e18;
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T = string, class U = char>
int character_count(T text, U character) {
int ans = 0;
for (U i : text) {
ans += (i == character);
}
return ans;
}
lint power(lint base, lint exponent, lint module) {
if (exponent % 2) {
return power(base, exponent - 1, module) * base % module;
} else if (exponent) {
lint root_ans = power(base, exponent / 2, module);
return root_ans * root_ans % module;
} else {
return 1;
}
}
struct position {
double y, x;
};
position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
double euclidean(position first, position second) {
return sqrt((second.x - first.x) * (second.x - first.x) +
(second.y - first.y) * (second.y - first.y));
}
double euclidean(double first, double second) {
return sqrt(first * first + second * second);
}
template <class T, class U> string to_string(pair<T, U> x) {
return to_string(x.first) + "," + to_string(x.second);
}
string to_string(string x) { return x; }
template <class itr> void array_output(itr start, itr goal) {
string ans;
for (auto i = start; i != goal; i++)
ans += to_string(*i) + " ";
if (!ans.empty())
ans.pop_back();
cout << ans << endl;
}
template <class itr> void cins(itr first, itr last) {
for (auto i = first; i != last; i++) {
cin >> (*i);
}
}
template <class T> T gcd(T a, T b) {
if (a && b) {
return gcd(min(a, b), max(a, b) % min(a, b));
} else {
return a;
}
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
struct combination {
vector<lint> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2, mod);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
lint P(int n, int r) {
if (r < 0 || n < r)
return 0;
return (fact[n] * inv[n - r] % mod);
}
lint C(int p, int q) {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
template <class itr> bool next_sequence(itr first, itr last, int max_bound) {
itr now = last;
while (now != first) {
now--;
(*now)++;
if ((*now) == max_bound) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
template <class itr, class itr2>
bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2) {
itr now = last;
itr2 now2 = last2;
while (now != first) {
now--, now2--;
(*now)++;
if ((*now) == (*now2)) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
inline int at(lint i, int j) { return (i >> j) & 1; }
int main() {
int N, K;
cin >> N >> K;
int a[N];
cins(a, a + N);
int a_copy[N];
for (int i = 0; i < N; i++) {
a_copy[i] = a[i];
a[i] = max(0, K + 1 - a[i]);
}
vector<int> pardon{-1};
for (int i = 0; i < K; i++) {
int max_pos = !pardon.back();
for (int j = 0; j < N; j++) {
if (a[j] > a[max_pos] && j != pardon.back()) {
max_pos = j;
}
}
pardon.push_back(max_pos);
a[max_pos] = max(a[max_pos] - 1, 0);
}
if (accumulate(a, a + N, 0)) {
cout << -1 << endl;
return 0;
}
// array_output(all(pardon));
vector<int> ans;
for (int i = 0; i < K; i++) {
for (int j = 0; j < N; j++) {
if (pardon[i] != j && pardon[i + 1] != j) {
ans.push_back(j + 1);
}
}
ans.push_back(pardon[i + 1] + 1);
}
for (int j = 0; j < N; j++) {
if (pardon[K] != j) {
ans.push_back(j + 1);
}
}
int cnt[N];
fill(cnt, cnt + N, 0);
for (int i : ans) {
cnt[i - 1]++;
}
for (int i = 0; i < N; i++) {
assert(cnt[i] <= a_copy[i]);
}
cout << ans.size() << endl;
array_output(all(ans));
}
| replace | 144 | 145 | 144 | 145 | 0 | |
p03114 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double louble;
template <typename T1, typename T2> inline T1 max(T1 a, T2 b) {
return a < b ? b : a;
}
template <typename T1, typename T2> inline T1 min(T1 a, T2 b) {
return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
if (s == t) {
t = (s = buf) + fread(buf, 1, bufl, stdin);
if (s == t)
return EOF;
}
return *s++;
}
inline int ty() {
int a = 0, b = 1, c = fetch();
while (!isdigit(c))
b ^= c == '-', c = fetch();
while (isdigit(c))
a = a * 10 + c - 48, c = fetch();
return b ? a : -a;
}
} // namespace ae86
using ae86::ty;
#define pick(a, b) (((a) >> (b)) & 1)
const int _ = 17, __ = _ + _, _s = 1 << 15, mo = 1000000007;
inline lint powa(lint a, lint t) {
lint b = 1;
while (t) {
if (t & 1)
b = b * a % mo;
a = a * a % mo, t >>= 1;
}
return b;
}
inline lint inva(lint a) { return powa(a, mo - 2); }
const lint inv9 = inva(9);
int bfa[__] = {0}, col[__] = {0}, ccnt = 0, cc;
int findbfa(int x) { return bfa[x] == x ? x : bfa[x] = findbfa(bfa[x]); }
inline void linka(int a, int b) { bfa[findbfa(b)] = findbfa(a); }
int n, m, ql[_], qr[_], xl[__], xr[__], ha[__], lha;
lint val[__] = {0}, f[9][_s] = {0}, coef[_s] = {0};
int main() {
ios::sync_with_stdio(0), cout.tie(nullptr);
n = ty(), m = ty(), lha = 0;
for (int i = 0; i < m; i++)
ha[lha++] = ql[i] = ty() - 1, ha[lha++] = qr[i] = ty();
ha[lha++] = 0, sort(ha, ha + lha), lha = unique(ha, ha + lha) - ha;
for (int i = 0; i < lha; i++)
bfa[i] = i;
for (int i = 0; i < m; i++) {
ql[i] = lower_bound(ha, ha + lha, ql[i]) - ha;
qr[i] = lower_bound(ha, ha + lha, qr[i]) - ha;
linka(ql[i], qr[i]);
}
for (int i = 0; i < lha; i++)
if (findbfa(i) == i)
col[i] = ccnt++;
for (int i = 0; i < lha; i++)
col[i] = col[findbfa(i)];
lint bas = inv9;
for (int i = 1; i < lha; i++) {
xl[i] = col[i], xr[i] = col[i - 1];
lint temp = (powa(10, ha[i] - ha[i - 1]) - 1 + mo) % mo * inv9 % mo;
bas = bas * temp % mo, val[i] = (temp + 1) * inva(temp) % mo;
}
if (ha[lha - 1] < n)
bas = bas * powa(10, n - ha[lha - 1]) % mo;
cc = 1 << ccnt;
for (int i = 0; i < cc; i++) {
coef[i] = 1;
for (int j = 1; j < lha; j++)
if (pick(i, xl[j]) && pick(i, xr[j]))
coef[i] = coef[i] * val[j] % mo;
f[0][i] = coef[i];
}
for (int i = 0; i < 8; i++)
for (int j = 0; j < cc; j++)
for (int k = cc - 1 - j; k >= 0; k = (k - 1) & (cc - 1 - j)) {
f[i + 1][j + k] = (f[i + 1][j + k] + f[i][j] * coef[k] % mo) % mo;
if (k <= 0)
break;
}
cout << bas * f[8][cc - 1] % mo << lf;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double louble;
template <typename T1, typename T2> inline T1 max(T1 a, T2 b) {
return a < b ? b : a;
}
template <typename T1, typename T2> inline T1 min(T1 a, T2 b) {
return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
if (s == t) {
t = (s = buf) + fread(buf, 1, bufl, stdin);
if (s == t)
return EOF;
}
return *s++;
}
inline int ty() {
int a = 0, b = 1, c = fetch();
while (!isdigit(c))
b ^= c == '-', c = fetch();
while (isdigit(c))
a = a * 10 + c - 48, c = fetch();
return b ? a : -a;
}
} // namespace ae86
using ae86::ty;
#define pick(a, b) (((a) >> (b)) & 1)
const int _ = 17, __ = _ + _, _s = 1 << 16, mo = 1000000007;
inline lint powa(lint a, lint t) {
lint b = 1;
while (t) {
if (t & 1)
b = b * a % mo;
a = a * a % mo, t >>= 1;
}
return b;
}
inline lint inva(lint a) { return powa(a, mo - 2); }
const lint inv9 = inva(9);
int bfa[__] = {0}, col[__] = {0}, ccnt = 0, cc;
int findbfa(int x) { return bfa[x] == x ? x : bfa[x] = findbfa(bfa[x]); }
inline void linka(int a, int b) { bfa[findbfa(b)] = findbfa(a); }
int n, m, ql[_], qr[_], xl[__], xr[__], ha[__], lha;
lint val[__] = {0}, f[9][_s] = {0}, coef[_s] = {0};
int main() {
ios::sync_with_stdio(0), cout.tie(nullptr);
n = ty(), m = ty(), lha = 0;
for (int i = 0; i < m; i++)
ha[lha++] = ql[i] = ty() - 1, ha[lha++] = qr[i] = ty();
ha[lha++] = 0, sort(ha, ha + lha), lha = unique(ha, ha + lha) - ha;
for (int i = 0; i < lha; i++)
bfa[i] = i;
for (int i = 0; i < m; i++) {
ql[i] = lower_bound(ha, ha + lha, ql[i]) - ha;
qr[i] = lower_bound(ha, ha + lha, qr[i]) - ha;
linka(ql[i], qr[i]);
}
for (int i = 0; i < lha; i++)
if (findbfa(i) == i)
col[i] = ccnt++;
for (int i = 0; i < lha; i++)
col[i] = col[findbfa(i)];
lint bas = inv9;
for (int i = 1; i < lha; i++) {
xl[i] = col[i], xr[i] = col[i - 1];
lint temp = (powa(10, ha[i] - ha[i - 1]) - 1 + mo) % mo * inv9 % mo;
bas = bas * temp % mo, val[i] = (temp + 1) * inva(temp) % mo;
}
if (ha[lha - 1] < n)
bas = bas * powa(10, n - ha[lha - 1]) % mo;
cc = 1 << ccnt;
for (int i = 0; i < cc; i++) {
coef[i] = 1;
for (int j = 1; j < lha; j++)
if (pick(i, xl[j]) && pick(i, xr[j]))
coef[i] = coef[i] * val[j] % mo;
f[0][i] = coef[i];
}
for (int i = 0; i < 8; i++)
for (int j = 0; j < cc; j++)
for (int k = cc - 1 - j; k >= 0; k = (k - 1) & (cc - 1 - j)) {
f[i + 1][j + k] = (f[i + 1][j + k] + f[i][j] * coef[k] % mo) % mo;
if (k <= 0)
break;
}
cout << bas * f[8][cc - 1] % mo << lf;
return 0;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p03114 | C++ | Runtime Error | /*{{{*/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASET \
int ___T; \
scanf("%d", &___T); \
for (int cs = 1; cs <= ___T; cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
_R(head);
R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
_W(x.F);
putchar(' ');
_W(x.S);
}
template <class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++))
if (i != x.cbegin())
putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
_W(head);
putchar(sizeof...(tail) ? ' ' : '\n');
W(tail...);
}
#ifdef HOME
#define DEBUG(...) \
{ \
printf("# "); \
printf(__VA_ARGS__); \
puts(""); \
}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL &x, LL v) {
x += v;
if (x >= MOD)
x -= MOD;
}
/*}}}*/
const int SIZE = 30;
LL mypow(LL x, LL y) {
x %= MOD;
LL res = 1 % MOD;
while (y) {
if (y & 1)
res = res * x % MOD;
y >>= 1;
x = x * x % MOD;
}
return res;
}
void my_mul(LL &x, LL v) { x = x * v % MOD; }
int get_bit(int x, int v) { return (x >> v) & 1; }
LL ten[33], one[33];
void init() {
ten[0] = 10;
one[0] = 1;
REPP(i, 1, 33) {
ten[i] = ten[i - 1] * ten[i - 1] % MOD;
one[i] = (one[i - 1] * ten[i - 1] + one[i - 1]) % MOD;
}
}
LL eleven(int n) {
LL now = 0;
for (int i = 0; n >> i; i++) {
if (get_bit(n, i)) {
now = (now * ten[i] + one[i]) % MOD;
}
}
return now;
}
int AA[SIZE];
VI aa[SIZE];
int type_num;
int e[SIZE][2];
int d[SIZE], dn;
int ee[SIZE];
int id[SIZE];
int ty[SIZE];
int N, Q;
LL mul[SIZE], mulmul[SIZE];
VI order, unorder;
LL dfs(int x, LL now, int num) {
if (x == SZ(order)) {
for (int y : unorder) {
LL val[9] = {};
fill(val, val + 9, 1);
LL for_all = 1;
for (int pos : aa[y]) {
if (pos && id[pos - 1] != id[pos]) {
my_mul(for_all, mul[pos]);
my_mul(val[ty[id[pos - 1]]], mulmul[pos]);
}
if (pos + 1 < dn && id[pos + 1] != id[pos]) {
my_mul(for_all, mul[pos + 1]);
my_mul(val[ty[id[pos + 1]]], mulmul[pos + 1]);
}
}
LL ss = 0;
REP(i, 9) { ADD(ss, val[i]); }
my_mul(now, ss * for_all % MOD);
}
return now;
}
LL sum = 0;
FOR(v, 0, num) {
ty[order[x]] = v;
LL tmp = 1;
for (int pos : aa[order[x]]) {
if (pos && id[pos - 1] != id[pos] && ty[id[pos - 1]] != -1) {
my_mul(tmp, mul[pos] + (ty[id[pos - 1]] == v));
}
if (pos + 1 < dn && id[pos + 1] != id[pos] && ty[id[pos + 1]] != -1) {
my_mul(tmp, mul[pos + 1] + (ty[id[pos + 1]] == v));
}
}
if (v == num) {
if (num < 9)
ADD(sum, dfs(x + 1, now * tmp % MOD * (9 - num) % MOD, num + 1));
} else {
ADD(sum, dfs(x + 1, now * tmp % MOD, num));
}
}
ty[order[x]] = -1;
return sum;
}
int main() {
init();
R(N, Q);
REP(i, Q) {
int x, y;
R(x, y);
x--;
e[i][0] = x;
e[i][1] = y;
d[dn++] = x;
d[dn++] = y;
}
sort(d, d + dn);
dn = unique(d, d + dn) - d;
REPP(i, 1, dn) {
mul[i] = eleven(d[i] - d[i - 1]);
mulmul[i] = (mul[i] + 1) * mypow(mul[i], MOD - 2) % MOD;
}
REP(i, Q) {
REP(j, 2) e[i][j] = lower_bound(d, d + dn, e[i][j]) - d;
ee[e[i][0]] |= 1 << e[i][1];
ee[e[i][1]] |= 1 << e[i][0];
}
REP(k, dn) REP(i, dn) REP(j, dn) {
if (get_bit(ee[i], k) && get_bit(ee[k], j))
ee[i] |= 1 << j;
}
LL base = mypow(10, d[0] + N - d[dn - 1]);
int good_mask;
{
int need = 0;
REP(i, dn - 1) {
if (!get_bit(ee[i], i + 1))
need |= 1 << i;
else
my_mul(base, mul[i + 1] + 1);
}
int tmp = 0;
bool u[SIZE] = {};
REP(i, dn) {
if (!u[i]) {
REP(j, dn) {
if (get_bit(ee[i], j) || i == j) {
AA[tmp] |= 1 << j;
aa[tmp].PB(j);
u[j] = 1;
id[j] = tmp;
}
}
tmp++;
}
}
type_num = tmp;
int mi = 100;
for (int i = 1; i < (1 << type_num); i++) {
int me = AA[0] | (AA[0] >> 1);
REPP(j, 1, type_num) {
if (get_bit(i, j))
me |= AA[j] | (AA[j] >> 1);
}
if ((need & me) == need) {
int bn = __builtin_popcount(i);
if (bn < mi) {
mi = bn;
good_mask = i;
}
}
}
REP(i, type_num) {
if (get_bit(good_mask, i))
order.PB(i);
else
unorder.PB(i);
}
}
MS1(ty);
ty[order[0]] = 0;
W(dfs(1, 1, 1) * base % MOD);
return 0;
}
| /*{{{*/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASET \
int ___T; \
scanf("%d", &___T); \
for (int cs = 1; cs <= ___T; cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
_R(head);
R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
_W(x.F);
putchar(' ');
_W(x.S);
}
template <class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++))
if (i != x.cbegin())
putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
_W(head);
putchar(sizeof...(tail) ? ' ' : '\n');
W(tail...);
}
#ifdef HOME
#define DEBUG(...) \
{ \
printf("# "); \
printf(__VA_ARGS__); \
puts(""); \
}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL &x, LL v) {
x += v;
if (x >= MOD)
x -= MOD;
}
/*}}}*/
const int SIZE = 30;
LL mypow(LL x, LL y) {
x %= MOD;
LL res = 1 % MOD;
while (y) {
if (y & 1)
res = res * x % MOD;
y >>= 1;
x = x * x % MOD;
}
return res;
}
void my_mul(LL &x, LL v) { x = x * v % MOD; }
int get_bit(int x, int v) { return (x >> v) & 1; }
LL ten[33], one[33];
void init() {
ten[0] = 10;
one[0] = 1;
REPP(i, 1, 33) {
ten[i] = ten[i - 1] * ten[i - 1] % MOD;
one[i] = (one[i - 1] * ten[i - 1] + one[i - 1]) % MOD;
}
}
LL eleven(int n) {
LL now = 0;
for (int i = 0; n >> i; i++) {
if (get_bit(n, i)) {
now = (now * ten[i] + one[i]) % MOD;
}
}
return now;
}
int AA[SIZE];
VI aa[SIZE];
int type_num;
int e[SIZE][2];
int d[SIZE], dn;
int ee[SIZE];
int id[SIZE];
int ty[SIZE];
int N, Q;
LL mul[SIZE], mulmul[SIZE];
VI order, unorder;
LL dfs(int x, LL now, int num) {
if (x == SZ(order)) {
for (int y : unorder) {
LL val[9] = {};
fill(val, val + 9, 1);
LL for_all = 1;
for (int pos : aa[y]) {
if (pos && id[pos - 1] != id[pos]) {
my_mul(for_all, mul[pos]);
my_mul(val[ty[id[pos - 1]]], mulmul[pos]);
}
if (pos + 1 < dn && id[pos + 1] != id[pos]) {
my_mul(for_all, mul[pos + 1]);
my_mul(val[ty[id[pos + 1]]], mulmul[pos + 1]);
}
}
LL ss = 0;
REP(i, 9) { ADD(ss, val[i]); }
my_mul(now, ss * for_all % MOD);
}
return now;
}
LL sum = 0;
FOR(v, 0, num) {
ty[order[x]] = v;
LL tmp = 1;
for (int pos : aa[order[x]]) {
if (pos && id[pos - 1] != id[pos] && ty[id[pos - 1]] != -1) {
my_mul(tmp, mul[pos] + (ty[id[pos - 1]] == v));
}
if (pos + 1 < dn && id[pos + 1] != id[pos] && ty[id[pos + 1]] != -1) {
my_mul(tmp, mul[pos + 1] + (ty[id[pos + 1]] == v));
}
}
if (v == num) {
if (num < 9)
ADD(sum, dfs(x + 1, now * tmp % MOD * (9 - num) % MOD, num + 1));
} else {
ADD(sum, dfs(x + 1, now * tmp % MOD, num));
}
}
ty[order[x]] = -1;
return sum;
}
int main() {
init();
R(N, Q);
REP(i, Q) {
int x, y;
R(x, y);
x--;
e[i][0] = x;
e[i][1] = y;
d[dn++] = x;
d[dn++] = y;
}
sort(d, d + dn);
dn = unique(d, d + dn) - d;
REPP(i, 1, dn) {
mul[i] = eleven(d[i] - d[i - 1]);
mulmul[i] = (mul[i] + 1) * mypow(mul[i], MOD - 2) % MOD;
}
REP(i, Q) {
REP(j, 2) e[i][j] = lower_bound(d, d + dn, e[i][j]) - d;
ee[e[i][0]] |= 1 << e[i][1];
ee[e[i][1]] |= 1 << e[i][0];
}
REP(k, dn) REP(i, dn) REP(j, dn) {
if (get_bit(ee[i], k) && get_bit(ee[k], j))
ee[i] |= 1 << j;
}
LL base = mypow(10, d[0] + N - d[dn - 1]);
int good_mask;
{
int need = 0;
REP(i, dn - 1) {
if (!get_bit(ee[i], i + 1))
need |= 1 << i;
else
my_mul(base, mul[i + 1] + 1);
}
int tmp = 0;
bool u[SIZE] = {};
REP(i, dn) {
if (!u[i]) {
REP(j, dn) {
if (get_bit(ee[i], j) || i == j) {
AA[tmp] |= 1 << j;
aa[tmp].PB(j);
u[j] = 1;
id[j] = tmp;
}
}
tmp++;
}
}
type_num = tmp;
int mi = 100;
for (int i = 1; i < (1 << type_num); i++) {
int me = 0;
REP(j, type_num) {
if (get_bit(i, j))
me |= AA[j] | (AA[j] >> 1);
}
if ((need & me) == need) {
int bn = __builtin_popcount(i);
if (bn < mi) {
mi = bn;
good_mask = i;
}
}
}
REP(i, type_num) {
if (get_bit(good_mask, i))
order.PB(i);
else
unorder.PB(i);
}
}
MS1(ty);
ty[order[0]] = 0;
W(dfs(1, 1, 1) * base % MOD);
return 0;
}
| replace | 240 | 242 | 240 | 242 | 0 | |
p03114 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N, Q;
int L[20], R[20];
ll dp[10][1 << 15];
const ll mo = 1000000007;
ll modpow(ll a, ll n = mo - 2) {
ll r = 1;
a %= mo;
while (n)
r = r * ((n % 2) ? a : 1) % mo, a = a * a % mo, n >>= 1;
return r;
}
template <int um> class UF {
public:
vector<int> par, rank, cnt;
UF() {
par = rank = vector<int>(um, 0);
cnt = vector<int>(um, 1);
for (int i = 0; i < um; i++)
par[i] = i;
}
void reinit() {
int i;
FOR(i, um) rank[i] = 0, cnt[i] = 1, par[i] = i;
}
int operator[](int x) {
return (par[x] == x) ? (x) : (par[x] = operator[](par[x]));
}
int count(int x) { return cnt[operator[](x)]; }
int operator()(int x, int y) {
if ((x = operator[](x)) == (y = operator[](y)))
return x;
cnt[y] = cnt[x] = cnt[x] + cnt[y];
if (rank[x] > rank[y])
return par[x] = y;
rank[x] += rank[x] == rank[y];
return par[y] = x;
}
};
UF<40> uf;
vector<pair<int, int>> C[40];
int ID[40];
ll mul[1 << 20];
ll param(int len) {
ll a = (modpow(10, len) + 8);
ll b = (modpow(10, len) - 1);
return a * modpow(b) % mo;
}
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N >> Q;
vector<int> V;
FOR(i, Q) {
cin >> L[i] >> R[i];
L[i]--;
V.push_back(L[i]);
V.push_back(R[i]);
}
V.push_back(0);
sort(ALL(V));
V.erase(unique(ALL(V)), V.end());
FOR(i, Q) {
L[i] = lower_bound(ALL(V), L[i]) - V.begin();
R[i] = lower_bound(ALL(V), R[i]) - V.begin();
uf(L[i], R[i]);
}
Q = 0;
FOR(i, V.size()) {
C[uf[i]].push_back({V[i], i});
if (uf[i] == i)
Q++;
}
sort(C, C + 40);
reverse(C, C + 40);
int lef = 0;
FOR(i, Q) {
FORR(c, C[i]) {
ID[c.second] = i;
if (c.second == 0)
lef = 1 << i;
}
}
int mask;
FOR(mask, 1 << Q) {
mul[mask] = 1;
FOR(j, V.size() - 1)
if ((mask & (1 << ID[j])) &&
(mask & (1 << ID[j + 1])))(mul[mask] *= param(V[j + 1] - V[j])) %= mo;
}
dp[0][0] = 1;
FOR(i, 9) {
FOR(mask, 1 << Q) {
int cand = mask ^ ((1 << Q) - 1);
for (int sm = cand; sm >= 0; sm--) {
sm &= cand;
if (i == 0 && ((sm & lef) == 0))
continue;
if (i && (sm & lef))
continue;
(dp[i + 1][mask ^ sm] += dp[i][mask] * mul[sm]) %= mo;
}
}
}
ll base = modpow(10, N - V.back());
FOR(i, V.size() - 1)
base = base * (modpow(10, V[i + 1] - V[i]) - 1) % mo * modpow(9) % mo;
cout << base * dp[9][(1 << Q) - 1] % mo << endl;
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N, Q;
int L[20], R[20];
ll dp[10][1 << 16];
const ll mo = 1000000007;
ll modpow(ll a, ll n = mo - 2) {
ll r = 1;
a %= mo;
while (n)
r = r * ((n % 2) ? a : 1) % mo, a = a * a % mo, n >>= 1;
return r;
}
template <int um> class UF {
public:
vector<int> par, rank, cnt;
UF() {
par = rank = vector<int>(um, 0);
cnt = vector<int>(um, 1);
for (int i = 0; i < um; i++)
par[i] = i;
}
void reinit() {
int i;
FOR(i, um) rank[i] = 0, cnt[i] = 1, par[i] = i;
}
int operator[](int x) {
return (par[x] == x) ? (x) : (par[x] = operator[](par[x]));
}
int count(int x) { return cnt[operator[](x)]; }
int operator()(int x, int y) {
if ((x = operator[](x)) == (y = operator[](y)))
return x;
cnt[y] = cnt[x] = cnt[x] + cnt[y];
if (rank[x] > rank[y])
return par[x] = y;
rank[x] += rank[x] == rank[y];
return par[y] = x;
}
};
UF<40> uf;
vector<pair<int, int>> C[40];
int ID[40];
ll mul[1 << 20];
ll param(int len) {
ll a = (modpow(10, len) + 8);
ll b = (modpow(10, len) - 1);
return a * modpow(b) % mo;
}
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N >> Q;
vector<int> V;
FOR(i, Q) {
cin >> L[i] >> R[i];
L[i]--;
V.push_back(L[i]);
V.push_back(R[i]);
}
V.push_back(0);
sort(ALL(V));
V.erase(unique(ALL(V)), V.end());
FOR(i, Q) {
L[i] = lower_bound(ALL(V), L[i]) - V.begin();
R[i] = lower_bound(ALL(V), R[i]) - V.begin();
uf(L[i], R[i]);
}
Q = 0;
FOR(i, V.size()) {
C[uf[i]].push_back({V[i], i});
if (uf[i] == i)
Q++;
}
sort(C, C + 40);
reverse(C, C + 40);
int lef = 0;
FOR(i, Q) {
FORR(c, C[i]) {
ID[c.second] = i;
if (c.second == 0)
lef = 1 << i;
}
}
int mask;
FOR(mask, 1 << Q) {
mul[mask] = 1;
FOR(j, V.size() - 1)
if ((mask & (1 << ID[j])) &&
(mask & (1 << ID[j + 1])))(mul[mask] *= param(V[j + 1] - V[j])) %= mo;
}
dp[0][0] = 1;
FOR(i, 9) {
FOR(mask, 1 << Q) {
int cand = mask ^ ((1 << Q) - 1);
for (int sm = cand; sm >= 0; sm--) {
sm &= cand;
if (i == 0 && ((sm & lef) == 0))
continue;
if (i && (sm & lef))
continue;
(dp[i + 1][mask ^ sm] += dp[i][mask] * mul[sm]) %= mo;
}
}
}
ll base = modpow(10, N - V.back());
FOR(i, V.size() - 1)
base = base * (modpow(10, V[i + 1] - V[i]) - 1) % mo * modpow(9) % mo;
cout << base * dp[9][(1 << Q) - 1] % mo << endl;
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03114 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 16;
namespace {
inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline int kissme(int x, int y) {
int c = 1;
while (y) {
if (y & 1) {
c = mul(c, x);
}
x = mul(x, x);
y >>= 1;
}
return c;
}
} // namespace
int n, Q, scnt, l[N], r[N], h[N], f[10][1 << 15];
bool vis[N << 1];
vector<int> all, vec[N], g[N << 1];
int get(int x) {
if (!x) {
return 1;
}
return mul(sub(kissme(10, x), 1), kissme(9, mod - 2));
}
int calc(vector<int> a) {
sort(a.begin(), a.end());
int ans = 1;
for (int i = 1; i < a.size(); i++) {
if (a[i] - a[i - 1] == 1) {
int x = get(all[a[i]] - all[a[i - 1]]);
ans = mul(ans, mul(add(x, 1), kissme(x, mod - 2)));
}
}
return ans;
}
void dfs(int s, int x) {
vis[x] = true;
vec[s].push_back(x);
for (int v : g[x]) {
if (!vis[v]) {
dfs(s, v);
}
}
}
int main(void) {
scanf("%d%d", &n, &Q);
for (int i = 1; i <= Q; i++) {
scanf("%d%d", &l[i], &r[i]);
l[i]--;
all.push_back(l[i]);
all.push_back(r[i]);
}
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
for (int i = 1; i <= Q; i++) {
l[i] = lower_bound(all.begin(), all.end(), l[i]) - all.begin();
r[i] = lower_bound(all.begin(), all.end(), r[i]) - all.begin();
g[l[i]].push_back(r[i]);
g[r[i]].push_back(l[i]);
}
for (int i = 0; i < all.size(); i++) {
if (!vis[i]) {
dfs(scnt++, i);
}
}
for (int i = 0; i < (1 << scnt); i++) {
vector<int> cur;
for (int j = 0; j < scnt; j++) {
if (i >> j & 1) {
for (int k : vec[j]) {
cur.push_back(k);
}
}
}
h[i] = calc(cur);
}
f[0][0] = 1;
for (int o = 0; o < 9; o++) {
for (int i = 0; i < (1 << scnt); i++) {
if (!f[o][i]) {
continue;
}
int t = (1 << scnt) - 1 - i;
for (int j = t;; j = t & (j - 1)) {
f[o + 1][i | j] = add(f[o + 1][i | j], mul(f[o][i], h[j]));
if (!j) {
break;
}
}
}
}
int ans = mul(f[9][(1 << scnt) - 1], kissme(10, all[0]));
for (int i = 1; i < all.size(); i++) {
ans = mul(ans, get(all[i] - all[i - 1]));
}
cout << mul(mul(ans, kissme(10, n - all.back())), kissme(9, mod - 2)) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 16;
namespace {
inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline int kissme(int x, int y) {
int c = 1;
while (y) {
if (y & 1) {
c = mul(c, x);
}
x = mul(x, x);
y >>= 1;
}
return c;
}
} // namespace
int n, Q, scnt, l[N], r[N], h[1 << N], f[10][1 << N];
bool vis[N << 1];
vector<int> all, vec[N], g[N << 1];
int get(int x) {
if (!x) {
return 1;
}
return mul(sub(kissme(10, x), 1), kissme(9, mod - 2));
}
int calc(vector<int> a) {
sort(a.begin(), a.end());
int ans = 1;
for (int i = 1; i < a.size(); i++) {
if (a[i] - a[i - 1] == 1) {
int x = get(all[a[i]] - all[a[i - 1]]);
ans = mul(ans, mul(add(x, 1), kissme(x, mod - 2)));
}
}
return ans;
}
void dfs(int s, int x) {
vis[x] = true;
vec[s].push_back(x);
for (int v : g[x]) {
if (!vis[v]) {
dfs(s, v);
}
}
}
int main(void) {
scanf("%d%d", &n, &Q);
for (int i = 1; i <= Q; i++) {
scanf("%d%d", &l[i], &r[i]);
l[i]--;
all.push_back(l[i]);
all.push_back(r[i]);
}
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
for (int i = 1; i <= Q; i++) {
l[i] = lower_bound(all.begin(), all.end(), l[i]) - all.begin();
r[i] = lower_bound(all.begin(), all.end(), r[i]) - all.begin();
g[l[i]].push_back(r[i]);
g[r[i]].push_back(l[i]);
}
for (int i = 0; i < all.size(); i++) {
if (!vis[i]) {
dfs(scnt++, i);
}
}
for (int i = 0; i < (1 << scnt); i++) {
vector<int> cur;
for (int j = 0; j < scnt; j++) {
if (i >> j & 1) {
for (int k : vec[j]) {
cur.push_back(k);
}
}
}
h[i] = calc(cur);
}
f[0][0] = 1;
for (int o = 0; o < 9; o++) {
for (int i = 0; i < (1 << scnt); i++) {
if (!f[o][i]) {
continue;
}
int t = (1 << scnt) - 1 - i;
for (int j = t;; j = t & (j - 1)) {
f[o + 1][i | j] = add(f[o + 1][i | j], mul(f[o][i], h[j]));
if (!j) {
break;
}
}
}
}
int ans = mul(f[9][(1 << scnt) - 1], kissme(10, all[0]));
for (int i = 1; i < all.size(); i++) {
ans = mul(ans, get(all[i] - all[i - 1]));
}
cout << mul(mul(ans, kissme(10, n - all.back())), kissme(9, mod - 2)) << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.