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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
s.at(k) = s.at(k) + 0x20;
for (int i = 0; i < s.size(); i++) {
cout << s.at(i);
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
s.at(k - 1) = s.at(k - 1) + 0x20;
for (int i = 0; i < s.size(); i++) {
cout << s.at(i);
}
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
string s;
getline(cin, s);
s.at(K - 1) = s.at(K - 1) + 0x20;
cout << s << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<char> s(N);
for (int i = 0; i < N; i++) {
cin >> s.at(i);
if (i == K - 1) {
s.at(i) += 0x20;
}
cout << s.at(i);
}
cout << endl;
} | replace | 6 | 10 | 6 | 15 | -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)
|
p03041 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main(void) {
int n, k;
cin >> n >> k;
char s[k];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
s[k - 1] += 32;
for (int i = 0; i < n; i++) {
cout << s[i];
}
cout << endl;
return 0;
} | #include <iostream>
using namespace std;
int main(void) {
int n, k;
cin >> n >> k;
char s[50];
cin >> s;
if (s[k - 1] == 'A')
s[k - 1] = 'a';
else if (s[k - 1] == 'B')
s[k - 1] = 'b';
else
s[k - 1] = 'c';
cout << s << endl;
} | replace | 5 | 15 | 5 | 14 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
string S;
cin >> S;
if (S.at(K) == 'A')
S.at(K) = 'a';
if (S.at(K) == 'B')
S.at(K) = 'b';
if (S.at(K) == 'C')
S.at(K) = 'c';
cout << S << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
string S;
cin >> S;
if (S.at(K - 1) == 'A')
S.at(K - 1) = 'a';
if (S.at(K - 1) == 'B')
S.at(K - 1) = 'b';
if (S.at(K - 1) == 'C')
S.at(K - 1) = 'c';
cout << S << endl;
} | replace | 8 | 14 | 8 | 14 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
string S;
S[B--] -= 32;
cout << S << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
string S;
cin >> S;
int C = B - 1;
cin >> C;
S[C] += 32;
cout << S << endl;
}
| replace | 7 | 8 | 7 | 11 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<char> x(N);
for (int i = 0; i < N; i++) {
cin >> x.at(i);
}
if (x.at(K) = 'A')
x.at(K) = 'a';
if (x.at(K) = 'B')
x.at(K) = 'b';
if (x.at(K) = 'C')
x.at(K) = 'c';
for (int j = 0; j < N; j++) {
cout << x.at(j);
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
char S[N + 1];
cin >> S;
if (S[K - 1] == 'A')
S[K - 1] = 'a';
if (S[K - 1] == 'B')
S[K - 1] = 'b';
if (S[K - 1] == 'C')
S[K - 1] = 'c';
cout << S << endl;
return 0;
}
| replace | 6 | 19 | 6 | 16 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
string c;
cin >> a >> b;
cin >> c;
if (c.at(b) == 'A')
c.at(b) == 'a';
if (c.at(b) == 'B')
c.at(b) == 'b';
if (c.at(b) == 'C')
c.at(b) == 'c';
cout << c << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
string c;
cin >> a >> b;
cin >> c;
if (c.at(b - 1) == 'A')
c.at(b - 1) = 'a';
if (c.at(b - 1) == 'B')
c.at(b - 1) = 'b';
if (c.at(b - 1) == 'C')
c.at(b - 1) = 'c';
cout << c << endl;
}
| replace | 8 | 14 | 8 | 15 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
if (s.at(k - 1) == 'A') {
s.at(k - 1) = 'a';
} else if (s.at(k) == 'B') {
s.at(k - 1) = 'b';
} else {
s.at(k - 1) = 'c';
}
cout << s << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
char in[55];
int a, b;
cin >> a >> b >> in;
in[b - 1] += 32;
cout << in << endl;
} | replace | 3 | 15 | 3 | 8 | 0 | |
p03041 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
char s[3];
for (int i = 0; i < n; i++)
cin >> s[i];
s[k - 1] = s[k - 1] + 32;
for (int i = 0; i < n; i++)
cout << s[i];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
char s[n];
for (int i = 0; i < n; i++)
cin >> s[i];
s[k - 1] = s[k - 1] + 32;
for (int i = 0; i < n; i++)
cout << s[i];
return 0;
} | replace | 6 | 7 | 6 | 7 | TLE | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
char a;
cin >> n >> k >> s;
a = s.at(k);
if (a == 'A') {
s.at(k - 1) = 'a';
} else if (a == 'B') {
s.at(k - 1) = 'b';
} else {
s.at(k - 1) = 'c';
}
cout << s << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
char a;
cin >> n >> k >> s;
a = s.at(k - 1);
if (a == 'A') {
s.at(k - 1) = 'a';
} else if (a == 'B') {
s.at(k - 1) = 'b';
} else {
s.at(k - 1) = 'c';
}
cout << s << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
string S;
(char)tolower(S.at(K - 1));
cout << S << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
string S;
cin >> N >> K >> S;
if (S.at(K - 1) == 'A')
S.at(K - 1) = 'a';
else if (S.at(K - 1) == 'B')
S.at(K - 1) = 'b';
else
S.at(K - 1) = 'c';
cout << S << endl;
} | replace | 5 | 6 | 5 | 12 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 32628) >= this->size() (which is 0)
|
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
string S;
cin >> S;
if (S.at(K) == 'A')
S.at(K) = 'a';
else if (S.at(K) == 'B')
S.at(K) = 'b';
else if (S.at(K) == 'C')
S.at(K) = 'c';
cout << S << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
string S;
cin >> S;
if (S.at(K - 1) == 'A')
S.at(K - 1) = 'a';
else if (S.at(K - 1) == 'B')
S.at(K - 1) = 'b';
else if (S.at(K - 1) == 'C')
S.at(K - 1) = 'c';
cout << S << endl;
} | replace | 8 | 14 | 8 | 14 | 0 | |
p03041 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int number, count;
string str;
cin >> number >> count;
cin >> str;
str.at(count) += 0x20;
cout << str << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int number, count;
string str;
cin >> number >> count;
cin >> str;
str.at(count - 1) += 0x20;
cout << str << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
char s[n];
cin >> n >> k;
cin >> s;
s[k - 1] += 32;
cout << s;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
char s[k];
cin >> n >> k;
cin >> s;
s[k - 1] += 32;
cout << s;
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
string S;
cin >> N >> K >> S;
S.at(K) = tolower(S.at(K));
cout << S;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
string S;
cin >> N >> K >> S;
S.at(K - 1) = tolower(S.at(K - 1));
cout << S;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03041 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// using
using namespace std;
// typedef
typedef long long ll;
typedef unsigned long long ull;
// assert
template <typename T> void assert_between(T val, T min, T max) {
assert(min <= val && val <= max);
}
// math
// 最大公約数(Gratest Common Divisor)を求める.
template <typename T> T gcd(T a, T b) {
assert(a > 0 && b > 0);
T num1 = max(a, b);
T num2 = min(a, b);
T mod = num1 % num2;
return (mod == 0) ? num2 : gcd(num2, mod);
}
// 最小公倍数(Least Common Multiple)を求める.
template <typename T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }
int N, K;
string S;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
scanf("%d %d", &N, &K);
cin >> S;
assert(S.length() == N);
switch (S[K - 1]) {
case 'A':
S[K - 1] = 'a';
break;
case 'B':
S[K - 1] = 'b';
break;
case 'C':
S[K - 1] = 'c';
break;
default:
assert(false);
break;
}
printf("%s\n", S.c_str());
}
| #include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// using
using namespace std;
// typedef
typedef long long ll;
typedef unsigned long long ull;
// assert
template <typename T> void assert_between(T val, T min, T max) {
assert(min <= val && val <= max);
}
// math
// 最大公約数(Gratest Common Divisor)を求める.
template <typename T> T gcd(T a, T b) {
assert(a > 0 && b > 0);
T num1 = max(a, b);
T num2 = min(a, b);
T mod = num1 % num2;
return (mod == 0) ? num2 : gcd(num2, mod);
}
// 最小公倍数(Least Common Multiple)を求める.
template <typename T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }
int N = INT32_MAX;
int K = INT32_MAX;
string S = "";
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
scanf("%d %d", &N, &K);
cin >> S;
assert(S.length() == N);
switch (S[K - 1]) {
case 'A':
S[K - 1] = 'a';
break;
case 'B':
S[K - 1] = 'b';
break;
case 'C':
S[K - 1] = 'c';
break;
default:
assert(false);
break;
}
printf("%s\n", S.c_str());
}
| replace | 44 | 46 | 44 | 47 | -6 | e424e92d-1952-4a8b-bfb4-0b4c97cdff4b.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03041/C++/s447244952.cpp:63: int main(): Assertion `S.length() == N' failed.
|
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
if (s.at(k) == 'A')
s.at(k) = 'a';
else if (s.at(k) == 'B')
s.at(k) = 'b';
else if (s.at(k) == 'C')
s.at(k) = 'c';
cout << s;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
if (s.at(k - 1) == 'A')
s.at(k - 1) = 'a';
else if (s.at(k - 1) == 'B')
s.at(k - 1) = 'b';
else if (s.at(k - 1) == 'C')
s.at(k - 1) = 'c';
cout << s;
} | replace | 8 | 14 | 8 | 14 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
char s[] = {};
cin >> n >> k;
cin >> s;
s[k - 1] = s[k - 1] + 32;
cout << s << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
char s[256];
cin >> n >> k;
cin >> s;
s[k - 1] = s[k - 1] + 32;
cout << s << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | -6 | *** stack smashing detected ***: terminated
|
p03041 | C++ | Runtime Error | #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
int main() {
int n, k;
std::string input, copy;
std::cin >> n >> k >> input;
copy = input;
transform(copy.begin(), copy.end(), copy.begin(),
[](unsigned char c) -> unsigned char { return std::tolower(c); });
input[k - 1] = copy[k - 1];
std::cout << input << std::endl;
return 1;
}
| #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
int main() {
int n, k;
std::string input, copy;
std::cin >> n >> k >> input;
copy = input;
transform(copy.begin(), copy.end(), copy.begin(),
[](unsigned char c) -> unsigned char { return std::tolower(c); });
input[k - 1] = copy[k - 1];
std::cout << input << std::endl;
return 0;
}
| replace | 18 | 19 | 18 | 19 | 1 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
s.at(k) = s.at(k) - ('A' - 'a');
cout << s << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
s.at(k - 1) = s.at(k - 1) - ('A' - 'a');
cout << s << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03041 | C++ | Runtime Error | /*
Author: Racer5x
*************************************** UNAUTHORISED COPYING OF CODE
PROHIBITED **********************************
*/
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
using namespace std;
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
bool mod(double a, double b) { return a / b - floor(a / b); }
bool f(int a, int b) { return a < b ? 0 : 1; }
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, x;
cin >> n >> x;
string s;
cin >> s;
s[x - 1] = s[x - 1] + ('a' - 'A');
cout << s;
} | /*
Author: Racer5x
*************************************** UNAUTHORISED COPYING OF CODE
PROHIBITED **********************************
*/
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
using namespace std;
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
bool mod(double a, double b) { return a / b - floor(a / b); }
bool f(int a, int b) { return a < b ? 0 : 1; }
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x;
cin >> n >> x;
string s;
cin >> s;
s[x - 1] = s[x - 1] + ('a' - 'A');
cout << s;
} | delete | 39 | 44 | 39 | 39 | -11 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
char s[10];
cin >> n >> k;
cin >> s;
s[k - 1] += 32;
cout << s;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
char s[49];
cin >> n >> k;
cin >> s;
s[k - 1] += 32;
cout << s;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
string S;
cin >> S;
if (S.at(K) == 'A')
S.at(K) = 'a';
if (S.at(K) == 'B')
S.at(K) = 'b';
if (S.at(K) == 'C')
S.at(K) = 'c';
cout << S << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
string S;
cin >> S;
if (S.at(K - 1) == 'A')
S.at(K - 1) = 'a';
if (S.at(K - 1) == 'B')
S.at(K - 1) = 'b';
if (S.at(K - 1) == 'C')
S.at(K - 1) = 'c';
cout << S << endl;
} | replace | 8 | 14 | 8 | 14 | 0 | |
p03041 | C++ | Runtime Error | /***************************************
Author : Susanka Majumder ( bingobong )
***************************************/
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#include <bits/stdc++.h>
using namespace std;
/* Template file for Online Algorithmic Competitions */
/* Typedefs */
/* Basic types */
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
/* STL containers */
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef set<int> si;
/* Macros */
/* Loops */
#define fl(i, a, b) for (int i(a); i <= (b); i++)
#define rep(i, n) fl(i, 1, (n))
#define loop(i, n) fl(i, 0, (n)-1)
#define rfl(i, a, b) for (int i(a); i >= (b); i--)
#define rrep(i, n) rfl(i, (n), 1)
/* Algorithmic functions */
#define pow2(x) ((x) * (x))
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define srt(v) sort((v).begin(), (v).end())
/* STL container methods */
#define pb push_back
#define mp make_pair
#define eb emplace_back
/* String methods */
#define dig(i) (s[i] - '0')
#define slen(s) s.length()
/* Shorthand notations */
#define fr first
#define sc second
#define re return
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define fill(x, y) memset(x, y, sizeof(x))
#define clr(a) fill(a, 0)
#define endl '\n'
/* Mathematical */
#define IINF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define PI 3.14159265358979323
#define NIL -1
/* Debugging purpose */
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
/* Fast Input Output */
#define FAST_IO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
/* Constants */
const ll MOD = 1000000007LL;
const ll MAX = 100010LL;
/* Templates */
template <class T> T abs(T x) { re x > 0 ? x : -x; }
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T power(T x, T y, ll m = MOD) {
T ans = 1;
x %= m;
while (y > 0) {
if (y & 1LL)
ans = (ans * x) % m;
y >>= 1LL;
x = (x * x) % m;
}
return ans % m;
}
/* additional*/
#define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
// double inf = 1.0/0.0;
int main() {
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\LENOVO\\Desktop\\input.txt", "r", stdin);
freopen("C:\\Users\\LENOVO\\Desktop\\output.txt", "w", stdout);
freopen("C:\\Users\\LENOVO\\Desktop\\error.txt", "w", stderr);
#endif
FAST_IO;
int a, b;
cin >> a >> b;
string s;
cin >> s;
s[b - 1] = (char)s[b - 1] + 32;
cout << s;
/* #ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif*/
return 0;
} | /***************************************
Author : Susanka Majumder ( bingobong )
***************************************/
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#include <bits/stdc++.h>
using namespace std;
/* Template file for Online Algorithmic Competitions */
/* Typedefs */
/* Basic types */
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
/* STL containers */
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef set<int> si;
/* Macros */
/* Loops */
#define fl(i, a, b) for (int i(a); i <= (b); i++)
#define rep(i, n) fl(i, 1, (n))
#define loop(i, n) fl(i, 0, (n)-1)
#define rfl(i, a, b) for (int i(a); i >= (b); i--)
#define rrep(i, n) rfl(i, (n), 1)
/* Algorithmic functions */
#define pow2(x) ((x) * (x))
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define srt(v) sort((v).begin(), (v).end())
/* STL container methods */
#define pb push_back
#define mp make_pair
#define eb emplace_back
/* String methods */
#define dig(i) (s[i] - '0')
#define slen(s) s.length()
/* Shorthand notations */
#define fr first
#define sc second
#define re return
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define fill(x, y) memset(x, y, sizeof(x))
#define clr(a) fill(a, 0)
#define endl '\n'
/* Mathematical */
#define IINF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define PI 3.14159265358979323
#define NIL -1
/* Debugging purpose */
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
/* Fast Input Output */
#define FAST_IO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
/* Constants */
const ll MOD = 1000000007LL;
const ll MAX = 100010LL;
/* Templates */
template <class T> T abs(T x) { re x > 0 ? x : -x; }
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T power(T x, T y, ll m = MOD) {
T ans = 1;
x %= m;
while (y > 0) {
if (y & 1LL)
ans = (ans * x) % m;
y >>= 1LL;
x = (x * x) % m;
}
return ans % m;
}
/* additional*/
#define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
// double inf = 1.0/0.0;
int main() {
/* #ifndef ONLINE_JUDGE
freopen("C:\\Users\\LENOVO\\Desktop\\input.txt","r",stdin);
freopen("C:\\Users\\LENOVO\\Desktop\\output.txt","w",stdout);
freopen("C:\\Users\\LENOVO\\Desktop\\error.txt","w",stderr);
#endif
*/
FAST_IO;
int a, b;
cin >> a >> b;
string s;
cin >> s;
s[b - 1] = (char)s[b - 1] + 32;
cout << s;
/* #ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif*/
return 0;
} | replace | 186 | 191 | 186 | 192 | -11 | |
p03041 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
//----------------
#define int long long
//----------------
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
#define sdf(x) x = read()
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define FFor(i, a, b) for (int i = (a); i >= (b); i--)
#define me(a, b) memset(a, b, sizeof(a))
#define mid ((l + ((r - l) / 2)))
#define random(a, b) ((a) + rand() % ((b) - (a) + 1))
#define bg1(x) cout << (#x) << ":" << (x) << " " << endl
#define bg2(x, y) \
cout << (#x) << ":" << (x) << " " << (#y) << ":" << (y) << " " << endl
#define bg3(x, y, z) \
cout << (#x) << ":" << (x) << " " << (#y) << ":" << (y) << " " << (#z) \
<< ":" << (z) << " " << endl
#define bg4(x, y, z, w) \
cout << (#x) << ":" << (x) << " " << (#y) << ":" << (y) << " " << (#z) \
<< ":" << (z) << " " << (#w) << ":" << (w) << " " << endl
#define bg5(x, y, z, w, k) \
cout << (#x) << ":" << (x) << " " << (#y) << ":" << (y) << " " << (#z) \
<< ":" << (z) << " " << (#w) << ":" << (w) << " " << (#k) << ":" << (k) \
<< " " << endl
#define call(x) cout << x << ":"
#define lll cout << "\n------\n"
int die = 0;
#define Die \
die++; \
if (die > 100000) { \
cout << "dead!!!"; \
exit(0); \
}
#define mk make_pair
#define pb push_back
const double eps = 1e-8;
// srand((unsigned)time(NULL));
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int n, k;
char s[N];
void sol1() {
s[k] = s[k] - 'A' + 'a';
printf("%s", s + 1);
}
void rd() {
sdf(n), sdf(k);
scanf("%s", s + 1);
sol1();
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
rd();
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
//----------------
#define int long long
//----------------
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
#define sdf(x) x = read()
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define FFor(i, a, b) for (int i = (a); i >= (b); i--)
#define me(a, b) memset(a, b, sizeof(a))
#define mid ((l + ((r - l) / 2)))
#define random(a, b) ((a) + rand() % ((b) - (a) + 1))
#define bg1(x) cout << (#x) << ":" << (x) << " " << endl
#define bg2(x, y) \
cout << (#x) << ":" << (x) << " " << (#y) << ":" << (y) << " " << endl
#define bg3(x, y, z) \
cout << (#x) << ":" << (x) << " " << (#y) << ":" << (y) << " " << (#z) \
<< ":" << (z) << " " << endl
#define bg4(x, y, z, w) \
cout << (#x) << ":" << (x) << " " << (#y) << ":" << (y) << " " << (#z) \
<< ":" << (z) << " " << (#w) << ":" << (w) << " " << endl
#define bg5(x, y, z, w, k) \
cout << (#x) << ":" << (x) << " " << (#y) << ":" << (y) << " " << (#z) \
<< ":" << (z) << " " << (#w) << ":" << (w) << " " << (#k) << ":" << (k) \
<< " " << endl
#define call(x) cout << x << ":"
#define lll cout << "\n------\n"
int die = 0;
#define Die \
die++; \
if (die > 100000) { \
cout << "dead!!!"; \
exit(0); \
}
#define mk make_pair
#define pb push_back
const double eps = 1e-8;
// srand((unsigned)time(NULL));
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int n, k;
char s[N];
void sol1() {
s[k] = s[k] - 'A' + 'a';
printf("%s", s + 1);
}
void rd() {
sdf(n), sdf(k);
scanf("%s", s + 1);
sol1();
}
signed main() { rd(); }
| replace | 80 | 87 | 80 | 81 | TLE | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
char x = s.at(k - 1);
if (x == 'A') {
x = 'a';
} else if (x == 'B') {
x = 'b';
} else {
x = 'c';
}
s.at(k - 1) = x;
cout << s << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k;
cin >> s;
char x = s.at(k - 1);
if (x == 'A') {
x = 'a';
} else if (x == 'B') {
x = 'b';
} else {
x = 'c';
}
s.at(k - 1) = x;
cout << s << endl;
}
| insert | 6 | 6 | 6 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 32533) >= this->size() (which is 0)
|
p03041 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
if (s.at(k) == 'A')
s.at(k) = 'a';
else if (s.at(k) == 'B')
s.at(k) = 'b';
else
s.at(k) = 'c';
cout << s << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
k = k - 1;
if (s.at(k) == 'A')
s.at(k) = 'a';
else if (s.at(k) == 'B')
s.at(k) = 'b';
else
s.at(k) = 'c';
cout << s << endl;
} | insert | 10 | 10 | 10 | 11 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
string S;
cin >> N >> K;
cin >> S;
S.at(K) = tolower(S.at(K - 1));
cout << S << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
string S;
cin >> N >> K;
cin >> S;
S.at(K - 1) = tolower(S.at(K - 1));
cout << S << endl;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03041 | C++ | Runtime Error | // TOPSIC001_0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b) \
for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) cout << " " << v[i]; \
cout << endl
#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;
int main() {
int N, K;
cin >> N >> K;
string S;
cin >> S;
S.at(K) = tolower(S.at(K));
cout << S;
return 0;
} | // TOPSIC001_0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b) \
for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) cout << " " << v[i]; \
cout << endl
#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;
int main() {
int N, K;
cin >> N >> K;
K--;
string S;
cin >> S;
S.at(K) = tolower(S.at(K));
cout << S;
return 0;
} | insert | 42 | 42 | 42 | 43 | 0 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
int K;
cin >> N;
cin >> K;
string S;
cin >> S;
S[K - 1] = S[K - 1] + 32;
cout << S << endl;
return 1;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
int K;
cin >> N;
cin >> K;
string S;
cin >> S;
S[K - 1] = S[K - 1] + 32;
cout << S << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 1 | |
p03041 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, B;
cin >> N >> B;
string S;
B--;
if (S.at(B) == 'A') {
S.at(B) = 'a';
cout << S << endl;
} else if (S.at(B) == 'B') {
S.at(B) = 'b';
cout << S << endl;
} else if (S.at(B) == 'C') {
S.at(B) = 'c';
cout << S << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, B;
cin >> N >> B;
string S;
cin >> S;
B--;
if (S.at(B) == 'A') {
S.at(B) = 'a';
cout << S << endl;
} else if (S.at(B) == 'B') {
S.at(B) = 'b';
cout << S << endl;
} else if (S.at(B) == 'C') {
S.at(B) = 'c';
cout << S << endl;
}
}
| insert | 7 | 7 | 7 | 8 | -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)
|
p03042 | Python | Runtime Error | s = input()
if s[:2] == "00" or s[2:] == "00":
print("NA")
elif s[:2] > 12 and 0 <= s[2:] <= 12:
print("YYMM")
elif 0 <= s[:2] <= 12 and 0 <= s[2:] <= 12:
print("AMBIGUOUS")
else:
print("MMYY")
| s = input()
f = 0 < int(s[:2]) < 13
s = 0 < int(s[2:]) < 13
ans = "NA"
if f and s:
ans = "AMBIGUOUS"
elif s:
ans = "YYMM"
elif f:
ans = "MMYY"
print(ans)
| replace | 1 | 9 | 1 | 12 | TypeError: '>' not supported between instances of 'str' and 'int' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03042/Python/s048876965.py", line 4, in <module>
elif s[:2] > 12 and 0 <= s[2:] <= 12:
TypeError: '>' not supported between instances of 'str' and 'int'
|
p03042 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
int a;
cin >> a;
int b = a / 100;
int c = a % 100;
if (b <= 12 && c <= 12 && b >= 1 && c >= 1) {
cout << "AMBIGIOUS" << endl;
} else if (b <= 12 && b >= 1 && c >= 1) {
cout << "MMYY" << endl;
} else if (b >= 1 && c >= 1 && c <= 12) {
cout << "YYMM" << endl;
} else
cout << "NA" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
scanf("%d", &a);
int L = a / 100;
int R = a % 100;
if (1 <= L && L <= 12) {
if (1 <= R && R <= 12)
printf("AMBIGUOUS\n");
else
printf("MMYY\n");
} else {
if (1 <= R && R <= 12)
printf("YYMM\n");
else
printf("NA\n");
}
} | replace | 3 | 16 | 3 | 17 | TLE | |
p03042 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;
int main() {
int s;
cin >> s;
vector<int> S(2);
S.at(0) = s / 100;
s = s % 100;
S.at(1) = s;
bool yymm = false;
bool mmyy = false;
if ((S.at(0) > 12 || S.at(0) == 0) && (S.at(1) > 12 || S.at(1) == 0))
cout << "NA";
else if ((S.at(0) > 12 || S.at(0) == 0) && (S.at(1) > 0 && S.at(1) < 13))
cout << "YYMM";
else if ((S.at(1) > 12 || S.at(1) == 0) && (S.at(2) > 0 && S.at(2) < 13))
cout << "MMYY";
else
cout << "AMBIGUOUS";
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;
int main() {
int s;
cin >> s;
vector<int> S(2);
S.at(0) = s / 100;
s = s % 100;
S.at(1) = s;
bool yymm = false;
bool mmyy = false;
if ((S.at(0) > 12 || S.at(0) == 0) && (S.at(1) > 12 || S.at(1) == 0))
cout << "NA";
else if ((S.at(0) > 12 || S.at(0) == 0) && (S.at(1) > 0 && S.at(1) < 13))
cout << "YYMM";
else if ((S.at(1) > 12 || S.at(1) == 0) && (S.at(0) > 0 && S.at(0) < 13))
cout << "MMYY";
else
cout << "AMBIGUOUS";
} | replace | 25 | 26 | 25 | 26 | 0 | |
p03042 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
int syc(long i, long Min, long Max) {
if (Min <= i && i <= Max) {
return 1;
} else {
exit(1);
// return 0;
}
}
int main() {
int x;
cin >> x;
syc(x, 1, 9999);
int b, c;
b = x / 100;
c = x % 100;
if ((1 <= b && b <= 12) && (1 <= c && c <= 12))
cout << "AMBIGUOUS" << endl;
else if (1 <= b && b <= 12)
cout << "MMYY" << endl;
else if (1 <= c && c <= 12)
cout << "YYMM" << endl;
else
cout << "NA" << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
int syc(long i, long Min, long Max) {
if (Min <= i && i <= Max) {
return 1;
} else {
exit(1);
// return 0;
}
}
int main() {
int x;
cin >> x;
syc(x, 0, 9999);
int b, c;
b = x / 100;
c = x % 100;
if ((1 <= b && b <= 12) && (1 <= c && c <= 12))
cout << "AMBIGUOUS" << endl;
else if (1 <= b && b <= 12)
cout << "MMYY" << endl;
else if (1 <= c && c <= 12)
cout << "YYMM" << endl;
else
cout << "NA" << endl;
return 0;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p03042 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
template <class T> void chmax(T &a, T b) {
if (a < b) {
a = b;
}
}
template <class T> void chmin(T &a, T b) {
if (a > b) {
a = b;
}
}
using namespace std;
int main(void) {
int s;
cin >> s;
int upper_half = s / 100;
int lower_half = s % (s / 100 * 100);
if (upper_half <= 12 && upper_half >= 1 && lower_half >= 1 &&
lower_half <= 12) {
cout << "AMBIGUOUS" << endl;
} else if (upper_half <= 12 && upper_half >= 1) {
cout << "MMYY" << endl;
} else if (lower_half >= 1 && lower_half <= 12) {
cout << "YYMM" << endl;
} else {
cout << "NA" << endl;
}
} | #include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
template <class T> void chmax(T &a, T b) {
if (a < b) {
a = b;
}
}
template <class T> void chmin(T &a, T b) {
if (a > b) {
a = b;
}
}
using namespace std;
int main(void) {
int s;
cin >> s;
int upper_half = s / 100;
int lower_half = upper_half == 0 ? s % 100 : s % (s / 100 * 100);
if (upper_half <= 12 && upper_half >= 1 && lower_half >= 1 &&
lower_half <= 12) {
cout << "AMBIGUOUS" << endl;
} else if (upper_half <= 12 && upper_half >= 1) {
cout << "MMYY" << endl;
} else if (lower_half >= 1 && lower_half <= 12) {
cout << "YYMM" << endl;
} else {
cout << "NA" << endl;
}
} | replace | 25 | 26 | 25 | 26 | 0 | |
p03042 | C++ | Runtime Error | #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
char s[4];
scanf("%s", s);
int i1 = (s[0] - '0') * 10 + (s[1] - '0');
int i2 = (s[2] - '0') * 10 + (s[3] - '0');
if (1 <= i1 && i1 <= 12) {
if (1 <= i2 && i2 <= 12) {
printf("AMBIGUOUS\n");
} else {
printf("MMYY\n");
}
} else {
if (1 <= i2 && i2 <= 12) {
printf("YYMM\n");
} else {
printf("NA\n");
}
}
}
| #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
char s[10];
scanf("%s", s);
int i1 = (s[0] - '0') * 10 + (s[1] - '0');
int i2 = (s[2] - '0') * 10 + (s[3] - '0');
if (1 <= i1 && i1 <= 12) {
if (1 <= i2 && i2 <= 12) {
printf("AMBIGUOUS\n");
} else {
printf("MMYY\n");
}
} else {
if (1 <= i2 && i2 <= 12) {
printf("YYMM\n");
} else {
printf("NA\n");
}
}
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03042 | C++ | Runtime Error | /*coderanant*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define f1(i, a, b) for (i = a; i < b; i++)
#define f2(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair
const int mod = 1000000007;
int i, j;
ll temp;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
string s;
cin >> s;
int m, y;
m = (s[0] - '0') * 10 + (s[1] - '0');
y = (s[2] - '0') * 10 + (s[3] - '0');
if (m >= 1 && m <= 12 && y <= 12 && y >= 1) {
cout << "AMBIGUOUS";
return 0;
} else if (m >= 1 && m <= 12) {
cout << "MMYY";
return 0;
} else if (y >= 1 && y <= 12) {
cout << "YYMM";
return 0;
} else
cout << "NA";
return 0;
} | /*coderanant*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define f1(i, a, b) for (i = a; i < b; i++)
#define f2(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair
const int mod = 1000000007;
int i, j;
ll temp;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// #endif
string s;
cin >> s;
int m, y;
m = (s[0] - '0') * 10 + (s[1] - '0');
y = (s[2] - '0') * 10 + (s[3] - '0');
if (m >= 1 && m <= 12 && y <= 12 && y >= 1) {
cout << "AMBIGUOUS";
return 0;
} else if (m >= 1 && m <= 12) {
cout << "MMYY";
return 0;
} else if (y >= 1 && y <= 12) {
cout << "YYMM";
return 0;
} else
cout << "NA";
return 0;
} | replace | 22 | 26 | 22 | 26 | 0 | |
p03042 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main(void) {
int num[2] = {0, 0};
string mes[4] = {"NA", "MMYY", "YYMM", "AMBIGUOUS"};
for (int i = 0; i < 3; i++) {
char c;
cin >> c;
num[i / 2] = num[i / 2] * 10 + (c - '0');
if (i % 2) {
num[i / 2] = (num[i / 2] > 0 && num[i / 2] <= 12) ? 1 : 0;
}
}
cout << mes[num[0] + num[1] * 2] << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main(void) {
int num[2] = {0, 0};
string mes[4] = {"NA", "MMYY", "YYMM", "AMBIGUOUS"};
for (int i = 0; i < 4; i++) {
char c;
cin >> c;
num[i / 2] = num[i / 2] * 10 + (c - '0');
if (i % 2) {
num[i / 2] = (num[i / 2] > 0 && num[i / 2] <= 12) ? 1 : 0;
}
}
cout << mes[num[0] + num[1] * 2] << endl;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03042 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack<int>
#define stll stack<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define stp setprecision(20) // use fixed before stp
#define endl '\n'
ll a[2000000];
int main() {
FAST
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
ll n;
cin >> n;
ll a = n % 100;
ll b = n / 100;
if ((a <= 12 && a != 0) && (b <= 12 && b != 0)) {
cout << "AMBIGUOUS";
} else if (a <= 12 && a != 0) {
cout << "YYMM";
} else if (b <= 12 && b != 0) {
cout << "MMYY";
} else
cout << "NA";
} | #include <bits/stdc++.h>
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack<int>
#define stll stack<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define stp setprecision(20) // use fixed before stp
#define endl '\n'
ll a[2000000];
int main() {
FAST ll n;
cin >> n;
ll a = n % 100;
ll b = n / 100;
if ((a <= 12 && a != 0) && (b <= 12 && b != 0)) {
cout << "AMBIGUOUS";
} else if (a <= 12 && a != 0) {
cout << "YYMM";
} else if (b <= 12 && b != 0) {
cout << "MMYY";
} else
cout << "NA";
} | replace | 32 | 38 | 32 | 33 | 0 | |
p03042 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int strtoint(string str) {
int res = 0;
int i = 0;
while (i < str.length() && str[i] >= '0' && str[i] <= '9') {
res *= 10;
res += str[i];
}
return res;
}
int main() {
string str;
cin >> str;
int former = strtoint(str.substr(0, 2));
int latter = strtoint(str.substr(2, 4));
if (former >= 1 && former <= 12) {
if (latter >= 1 && latter <= 12) {
cout << "AMBIGUOUS";
} else {
cout << "MMYY";
}
} else {
if (latter >= 1 && latter <= 12) {
cout << "YYMM";
} else {
cout << "NA";
}
}
} | #include <iostream>
#include <string>
using namespace std;
int strtoint(string str) {
int res = 0;
int i = 0;
while (i < str.length() && str[i] >= '0' && str[i] <= '9') {
res *= 10;
res += str[i] - 48;
i++;
}
return res;
}
int main() {
string str;
cin >> str;
int former = strtoint(str.substr(0, 2));
int latter = strtoint(str.substr(2, 4));
if (former >= 1 && former <= 12) {
if (latter >= 1 && latter <= 12) {
cout << "AMBIGUOUS";
} else {
cout << "MMYY";
}
} else {
if (latter >= 1 && latter <= 12) {
cout << "YYMM";
} else {
cout << "NA";
}
}
} | replace | 10 | 11 | 10 | 12 | TLE | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<pll> vplll;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
double n, k;
cin >> n >> k;
double ans = 0;
for (double i = 1; i <= n; ++i) {
if (i < k) {
double x = ceil(k / i);
x = ceil(log(x) / log(2));
ans += pow(0.5, x);
} else {
ans += 1;
}
}
ans *= 1 / n;
cout << setprecision(20) << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<pll> vplll;
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
double n, k;
cin >> n >> k;
double ans = 0;
for (double i = 1; i <= n; ++i) {
if (i < k) {
double x = ceil(k / i);
x = ceil(log(x) / log(2));
ans += pow(0.5, x);
} else {
ans += 1;
}
}
ans *= 1 / n;
cout << setprecision(20) << ans << endl;
return 0;
} | replace | 10 | 13 | 10 | 13 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define ALL(x) (x).begin(), (x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
int N, K;
scanf("%d%d", N, K);
double ans = 0;
for (int i = 1; i <= N; i++) {
int Point = i;
double rate = 1.0 / N;
while (Point < K) {
Point *= 2;
rate *= 0.5;
}
ans += rate;
}
printf("%.12f\n", ans);
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define ALL(x) (x).begin(), (x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
int N, K;
scanf("%d%d", &N, &K);
double ans = 0;
for (int i = 1; i <= N; i++) {
int Point = i;
double rate = 1.0 / N;
while (Point < K) {
Point *= 2;
rate *= 0.5;
}
ans += rate;
}
printf("%.12f\n", ans);
} | replace | 11 | 12 | 11 | 12 | -11 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) \
; \
for (long long i = 0; i < (n); i++)
using ll = long long;
using vl = vector<long long>;
using P = pair<long long, long long>;
int main() {
ll n, k;
cin >> n >> k;
vector<double> p(n, 1);
rep(i, n) p[i] /= n;
rep(i, k - 1) {
ll r = i + 1;
while (r < k) {
r *= 2;
p[i] /= 2;
}
}
double ans = 0;
rep(i, n) ans += p[i];
cout << fixed << setprecision(12);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) \
; \
for (long long i = 0; i < (n); i++)
using ll = long long;
using vl = vector<long long>;
using P = pair<long long, long long>;
int main() {
ll n, k;
cin >> n >> k;
vector<double> p(n, 1);
rep(i, n) p[i] /= n;
ll q = min(n, k - 1) rep(i, q) {
ll r = i + 1;
while (r < k) {
r *= 2;
p[i] /= 2;
}
}
double ans = 0;
rep(i, n) ans += p[i];
cout << fixed << setprecision(12);
cout << ans << endl;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<string, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF = 1LL << 60;
ll MOD = 1000000007;
ll N, K;
// dp[i]はiからコインふって勝つ確率
vector<double> dp(100005, -1);
double F(ll e) {
if (dp[e] != -1) {
return dp[e];
}
if (e >= K) {
return 1.0;
}
if (e <= 0) {
return 0.0;
} else
return dp[e] = 0.5 * F(2 * e);
}
int main() {
cin >> N;
cin >> K;
double ans = 0;
for (ll i = 1; i <= N; i++) {
ans += F(i) / N;
;
}
cout << fixed << setprecision(12);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<string, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF = 1LL << 60;
ll MOD = 1000000007;
ll N, K;
// dp[i]はiからコインふって勝つ確率
vector<double> dp(100005, -1);
double F(ll e) {
if (e >= 0 && e <= 100003 && dp[e] != -1) {
return dp[e];
}
if (e >= K) {
return 1.0;
}
if (e <= 0) {
return 0.0;
} else
return dp[e] = 0.5 * F(2 * e);
}
int main() {
cin >> N;
cin >> K;
double ans = 0;
for (ll i = 1; i <= N; i++) {
ans += F(i) / N;
;
}
cout << fixed << setprecision(12);
cout << ans << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03043 | C++ | Runtime Error | #include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
vector<int> db;
int rec(int i, int K) {
if (db[i] != -1)
return db[i];
if (i >= K) {
db[i] = 0;
return 0;
}
db[i] = rec(i * 2, K) + 1;
return db[i];
}
int main() {
int i, N, K, a, b, c;
double ans = 0.0;
cin >> N >> K;
db.resize(N * 2 + 10);
fill(db.begin(), db.end(), -1);
for (i = 1; i <= N; i++) {
a = rec(i, K);
b = 1 << a;
ans += 1.0 / (N * b);
}
// cout << std::fixed;
cout << std::setprecision(12) << ans << endl;
// cout << ans << endl;
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
vector<int> db;
int rec(int i, int K) {
if (db[i] != -1)
return db[i];
if (i >= K) {
db[i] = 0;
return 0;
}
db[i] = rec(i * 2, K) + 1;
return db[i];
}
int main() {
int i, N, K, a, b, c;
double ans = 0.0;
cin >> N >> K;
db.resize(max(N * 2 + 10, K * 2 + 10));
fill(db.begin(), db.end(), -1);
for (i = 1; i <= N; i++) {
a = rec(i, K);
b = 1 << a;
ans += 1.0 / (N * b);
}
// cout << std::fixed;
cout << std::setprecision(12) << ans << endl;
// cout << ans << endl;
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p03043 | C++ | Runtime Error | #include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
double ans = 0.0;
long long cnt_abs_win = 0LL;
int mx_bunbo = 0;
vector<int> bunbo, bunsi;
for (int i = 1; i <= N; i++) {
if (i >= K) {
cnt_abs_win++;
// ans += 1.0 / N;
} else {
int tmp = i;
int cnt = 0;
while (tmp < K) {
tmp *= 2;
cnt++;
}
int tmp_bunbo = pow(2, cnt);
if (tmp_bunbo >= mx_bunbo) {
bunbo.push_back(tmp_bunbo);
bunsi.push_back(1);
mx_bunbo = tmp_bunbo;
} else {
int tmp_bunsi = 1;
while (tmp_bunbo != mx_bunbo) {
tmp_bunbo *= 2;
tmp_bunsi *= 2;
}
bunbo.push_back(tmp_bunbo);
bunsi.push_back(tmp_bunsi);
}
}
}
int ans_bunbo = bunbo[0] * N;
int ans_bunsi =
accumulate(bunsi.begin(), bunsi.end(), 0) + cnt_abs_win * bunbo[0];
cout << fixed << setprecision(12) << (double)ans_bunsi / (double)ans_bunbo
<< endl;
return 0;
} | #include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
double ans = 0.0;
long long cnt_abs_win = 0LL;
int mx_bunbo = 0;
vector<int> bunbo, bunsi;
for (int i = 1; i <= N; i++) {
if (i >= K) {
cnt_abs_win++;
// ans += 1.0 / N;
} else {
int tmp = i;
int cnt = 0;
while (tmp < K) {
tmp *= 2;
cnt++;
}
int tmp_bunbo = pow(2, cnt);
if (tmp_bunbo >= mx_bunbo) {
bunbo.push_back(tmp_bunbo);
bunsi.push_back(1);
mx_bunbo = tmp_bunbo;
} else {
int tmp_bunsi = 1;
while (tmp_bunbo != mx_bunbo) {
tmp_bunbo *= 2;
tmp_bunsi *= 2;
}
bunbo.push_back(tmp_bunbo);
bunsi.push_back(tmp_bunsi);
}
}
}
int ans_bunbo;
int ans_bunsi;
if (bunbo.size() > 0) {
ans_bunbo = bunbo[0] * N;
ans_bunsi =
accumulate(bunsi.begin(), bunsi.end(), 0) + cnt_abs_win * bunbo[0];
} else {
ans_bunbo = 1;
ans_bunsi = 1;
}
cout << fixed << setprecision(12) << (double)ans_bunsi / (double)ans_bunbo
<< endl;
return 0;
}
| replace | 47 | 50 | 47 | 59 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using mii = map<int, int>;
long long divup(long long a, long long b);
long long kaijou(long long i);
long long P(long long n, long long k);
long long C(long long n, long long k);
long long GCD(long long a, long long b);
long long LCM(long long a, long long b);
bool prime(long long N);
double distance(vector<long long> p, vector<long long> q, long long n);
void press(vector<long long> &v);
void ranking(vector<long long> &v);
void erase(vector<long long> &v, long long i);
void unique(vector<long long> &v);
void printv(vector<long long> v);
// 端数繰りあがり割り算(検証済)
// a÷bの端数繰り上げ
// b!=0のデバグはしてないので分母に0を入れないように
// 負数対応
long long divup(long long a, long long b) {
long long x = abs(a);
long long y = abs(b);
long long z = (x + y - 1) / y;
if (b * a < 0)
return -z;
else
return z;
}
// 階乗
// 検証済み
long long kaijou(long long i) {
if (i == 0)
return 1;
long long j = 1;
for (long long k = 1; k <= i; k++) {
j *= k;
}
return j;
}
// 順列nPk(完成)
// n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数
// n<kなら0を返す
// 敢えて負数時のデバグはしてない
long long P(long long n, long long k) {
if (n < k)
return 0;
long long y = 1;
for (long long i = 0; i < k; i++) {
y *= (n - i);
}
return y;
}
// 組み合わせnCk(検証済み)
// P,kaijouと併用
long long C(long long n, long long k) {
if (n < k)
return 0;
return P(n, k) / kaijou(k);
}
// nHk
// 区別しないn個の要素を、区別するk個のグループに分ける
// 0個のグループがあっ
// て良い
// C必須
// 最大公約数GCD,最小公倍数LCM
// LCMを使うときはGCDをセットで
// 検証済み
long long GCD(long long a, long long b) {
if (a < b)
swap(a, b);
long long d = a % b;
if (d == 0) {
return b;
}
return GCD(b, d);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
// 素数判定
// 素数ならばtrue、素数以外の整数にはfalse
// 負数は全てfalse
// 検証済み
bool prime(long long N) {
if (N == 1) {
return false;
}
if (N < 0)
return false;
long long p = sqrt(N);
for (long long i = 2; i <= p; i++) {
if (N % i == 0) {
return false;
}
}
return true;
}
// ユークリッド距離
// 検証済み
// 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的)
double distance(vector<long long> p, vector<long long> q, long long n) {
double x = 0;
for (long long i = 0; i < n; i++) {
x += pow((p.at(i) - q.at(i)), 2);
}
return sqrt(x);
}
// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1, 0}にする
void press(vector<long long> &v) {
long long n = v.size();
vector<long long> w(n);
map<long long, long long> m;
for (auto &p : v) {
m[p] = 0;
}
long long i = 0;
for (auto &p : m) {
p.second = i;
i++;
}
for (long long i = 0; i < n; i++) {
w.at(i) = m[v.at(i)];
}
v = w;
return;
}
// 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数
// 配列の要素が全て異なるときにしか正常に動作しない
// 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、
// エラーも起きないので注意
// 検証済
//{2,4,1,6,0,3,8,9,5}を
//{4,2,0,5,1,8,3,6,7}にして返す
//"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意
void ranking(vector<long long> &v) {
long long n = v.size();
map<long long, long long> m;
long long i;
for (i = 0; i < n; i++) {
m[v.at(i)] = i;
}
vector<long long> w(n);
i = 0;
for (auto &p : m) {
v.at(i) = p.second;
i++;
}
return;
}
// 部分削除(未検証)
// ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、
// 以降の要素を全て前に1ずらして参照返し
// ベクトル長は1小さくなって返る
// i>n-1の時は変化しない
void erase(vector<long long> &v, long long i) {
long long n = v.size();
if (i > n - 1)
return;
for (long long j = i; j < n - 1; j++) {
v.at(j) = v.at(j + 1);
}
v.pop_back();
return;
}
// 重複削除(未完成)
// 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除
// 参照返し
// ベクトル長も変化する
// O(logn)くらい
void unique(vector<long long> &v) {
long long n = v.size();
set<long long> s;
long long i = 0;
while (i < n) {
if (s.count(v.at(i))) {
erase(v, i);
n--;
} else {
s.insert(v.at(i));
i++;
}
}
return;
}
// ベクトルの出力(検証済)
// debug用にvectorの中身を出力する
void printv(vector<long long> v) {
cout << "{ ";
for (auto &p : v) {
cout << p << ",";
}
cout << "}" << endl;
}
//////////////////////////////////////////////////////////////
// 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を
// 収納した長さnのベクトルを返す
// 未検証
vector<ll> keta(ll x) {
ll n = log10(x) + 1; // xの桁数
vll w(n, 0);
for (ll i = 0; i < n; i++) {
ll p;
p = x % 10;
x = x / 10;
w[n - 1 - i] = p;
}
return w;
}
// 1以上a以下に何個cまたはdで割り切れるものがあるか
// を返す
ll sch(ll a, ll c, ll d, ll mod) {
ll t, s, x = 0; // 割り切れる数の計算
t = a / mod;
s = a % mod;
ll yaku = mod / c + mod / d - 1;
x += s / c;
x += s / d;
x += t * yaku;
return x;
}
// まずはどちらかで割り切れる数を数える
int main() {
cout << fixed;
cout << setprecision(20);
ll n, k;
cin >> n >> k;
vll v(20);
ll i = 0;
ll m = k;
ll l;
while (m > 1) {
v[i] = m;
m = divup(m, 2); // i回の表で勝ちになれる最低値
i++;
}
// debug
// cout<<endl<<i<<endl;
v[i] = 1;
// n==10のとき
// v{10,5,3,2,1}
// debug
// printv(v);
double p = 0;
// 最低でも何回表を出さないと勝てないか調べる
ll t;
for (ll i = 0; i < n; i++) {
if (n >= v[i]) {
t = i;
break;
}
}
// debug
// cout<<t<<endl;
// k未満のときの勝率
for (ll j = t; j < i; j++) {
// j回表が必要な時の勝率
double q = pow(0.5, j + 1) * (v[j] - v[j + 1]);
// cout<<q<<endl;
p += q;
}
p = p + pow(0.5, t) * (n - v[t] + 1);
p = p / n;
cout << p;
}
| #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using mii = map<int, int>;
long long divup(long long a, long long b);
long long kaijou(long long i);
long long P(long long n, long long k);
long long C(long long n, long long k);
long long GCD(long long a, long long b);
long long LCM(long long a, long long b);
bool prime(long long N);
double distance(vector<long long> p, vector<long long> q, long long n);
void press(vector<long long> &v);
void ranking(vector<long long> &v);
void erase(vector<long long> &v, long long i);
void unique(vector<long long> &v);
void printv(vector<long long> v);
// 端数繰りあがり割り算(検証済)
// a÷bの端数繰り上げ
// b!=0のデバグはしてないので分母に0を入れないように
// 負数対応
long long divup(long long a, long long b) {
long long x = abs(a);
long long y = abs(b);
long long z = (x + y - 1) / y;
if (b * a < 0)
return -z;
else
return z;
}
// 階乗
// 検証済み
long long kaijou(long long i) {
if (i == 0)
return 1;
long long j = 1;
for (long long k = 1; k <= i; k++) {
j *= k;
}
return j;
}
// 順列nPk(完成)
// n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数
// n<kなら0を返す
// 敢えて負数時のデバグはしてない
long long P(long long n, long long k) {
if (n < k)
return 0;
long long y = 1;
for (long long i = 0; i < k; i++) {
y *= (n - i);
}
return y;
}
// 組み合わせnCk(検証済み)
// P,kaijouと併用
long long C(long long n, long long k) {
if (n < k)
return 0;
return P(n, k) / kaijou(k);
}
// nHk
// 区別しないn個の要素を、区別するk個のグループに分ける
// 0個のグループがあっ
// て良い
// C必須
// 最大公約数GCD,最小公倍数LCM
// LCMを使うときはGCDをセットで
// 検証済み
long long GCD(long long a, long long b) {
if (a < b)
swap(a, b);
long long d = a % b;
if (d == 0) {
return b;
}
return GCD(b, d);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
// 素数判定
// 素数ならばtrue、素数以外の整数にはfalse
// 負数は全てfalse
// 検証済み
bool prime(long long N) {
if (N == 1) {
return false;
}
if (N < 0)
return false;
long long p = sqrt(N);
for (long long i = 2; i <= p; i++) {
if (N % i == 0) {
return false;
}
}
return true;
}
// ユークリッド距離
// 検証済み
// 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的)
double distance(vector<long long> p, vector<long long> q, long long n) {
double x = 0;
for (long long i = 0; i < n; i++) {
x += pow((p.at(i) - q.at(i)), 2);
}
return sqrt(x);
}
// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1, 0}にする
void press(vector<long long> &v) {
long long n = v.size();
vector<long long> w(n);
map<long long, long long> m;
for (auto &p : v) {
m[p] = 0;
}
long long i = 0;
for (auto &p : m) {
p.second = i;
i++;
}
for (long long i = 0; i < n; i++) {
w.at(i) = m[v.at(i)];
}
v = w;
return;
}
// 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数
// 配列の要素が全て異なるときにしか正常に動作しない
// 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、
// エラーも起きないので注意
// 検証済
//{2,4,1,6,0,3,8,9,5}を
//{4,2,0,5,1,8,3,6,7}にして返す
//"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意
void ranking(vector<long long> &v) {
long long n = v.size();
map<long long, long long> m;
long long i;
for (i = 0; i < n; i++) {
m[v.at(i)] = i;
}
vector<long long> w(n);
i = 0;
for (auto &p : m) {
v.at(i) = p.second;
i++;
}
return;
}
// 部分削除(未検証)
// ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、
// 以降の要素を全て前に1ずらして参照返し
// ベクトル長は1小さくなって返る
// i>n-1の時は変化しない
void erase(vector<long long> &v, long long i) {
long long n = v.size();
if (i > n - 1)
return;
for (long long j = i; j < n - 1; j++) {
v.at(j) = v.at(j + 1);
}
v.pop_back();
return;
}
// 重複削除(未完成)
// 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除
// 参照返し
// ベクトル長も変化する
// O(logn)くらい
void unique(vector<long long> &v) {
long long n = v.size();
set<long long> s;
long long i = 0;
while (i < n) {
if (s.count(v.at(i))) {
erase(v, i);
n--;
} else {
s.insert(v.at(i));
i++;
}
}
return;
}
// ベクトルの出力(検証済)
// debug用にvectorの中身を出力する
void printv(vector<long long> v) {
cout << "{ ";
for (auto &p : v) {
cout << p << ",";
}
cout << "}" << endl;
}
//////////////////////////////////////////////////////////////
// 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を
// 収納した長さnのベクトルを返す
// 未検証
vector<ll> keta(ll x) {
ll n = log10(x) + 1; // xの桁数
vll w(n, 0);
for (ll i = 0; i < n; i++) {
ll p;
p = x % 10;
x = x / 10;
w[n - 1 - i] = p;
}
return w;
}
// 1以上a以下に何個cまたはdで割り切れるものがあるか
// を返す
ll sch(ll a, ll c, ll d, ll mod) {
ll t, s, x = 0; // 割り切れる数の計算
t = a / mod;
s = a % mod;
ll yaku = mod / c + mod / d - 1;
x += s / c;
x += s / d;
x += t * yaku;
return x;
}
// まずはどちらかで割り切れる数を数える
int main() {
cout << fixed;
cout << setprecision(20);
ll n, k;
cin >> n >> k;
vll v(20);
ll i = 0;
ll m = k;
ll l;
while (m > 1) {
v[i] = m;
m = divup(m, 2); // i回の表で勝ちになれる最低値
i++;
}
// debug
// cout<<endl<<i<<endl;
v[i] = 1;
// n==10のとき
// v{10,5,3,2,1}
// debug
// printv(v);
double p = 0;
// 最低でも何回表を出さないと勝てないか調べる
ll t;
for (ll i = 0; i < 20; i++) {
if (n >= v[i]) {
t = i;
break;
}
}
// debug
// cout<<t<<endl;
// k未満のときの勝率
for (ll j = t; j < i; j++) {
// j回表が必要な時の勝率
double q = pow(0.5, j + 1) * (v[j] - v[j + 1]);
// cout<<q<<endl;
p += q;
}
p = p + pow(0.5, t) * (n - v[t] + 1);
p = p / n;
cout << p;
}
| replace | 280 | 281 | 280 | 281 | 0 | |
p03043 | C++ | Runtime Error | #include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, k;
cin >> n >> k;
int cnt[200000];
for (int i = k * 2 - 1; i >= 1; i--) {
if (i % 2 == 0) {
cnt[i / 2] = cnt[i] + 1;
}
}
double p[25];
p[0] = 1.0;
for (int i = 0; i < 25 - 1; i++) {
p[i + 1] = p[i] * 0.5;
}
double ans = 0;
for (int i = 1; i <= n; i++) {
// cout << p[cnt[i]];
ans += (1.0 / n) * p[cnt[i]];
}
printf("%.12lf\n", ans);
return 0;
}
| #include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, k;
cin >> n >> k;
int cnt[500000];
for (int i = k * 2 - 1; i >= 1; i--) {
if (i % 2 == 0) {
cnt[i / 2] = cnt[i] + 1;
}
}
double p[25];
p[0] = 1.0;
for (int i = 0; i < 25 - 1; i++) {
p[i + 1] = p[i] * 0.5;
}
double ans = 0;
for (int i = 1; i <= n; i++) {
// cout << p[cnt[i]];
ans += (1.0 / n) * p[cnt[i]];
}
printf("%.12lf\n", ans);
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
double dp[10000]; // dp[i]: 現在の得点がiのときの勝率
int main() {
int N, K;
cin >> N >> K;
for (int i = K - 1; i >= 1; i--) {
dp[i] = 0.5 * (i * 2 >= K ? 1.0 : dp[i * 2]) + 0.5 * 0;
}
double ans = 0;
for (int i = 1; i <= N; i++) {
ans += (i >= K ? 1.0 : dp[i]) / N;
}
cout << fixed << setprecision(12) << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
double dp[100000]; // dp[i]: 現在の得点がiのときの勝率
int main() {
int N, K;
cin >> N >> K;
for (int i = K - 1; i >= 1; i--) {
dp[i] = 0.5 * (i * 2 >= K ? 1.0 : dp[i * 2]) + 0.5 * 0;
}
double ans = 0;
for (int i = 1; i <= N; i++) {
ans += (i >= K ? 1.0 : dp[i]) / N;
}
cout << fixed << setprecision(12) << ans << '\n';
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03043 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define intv vector<v>
#define llv vector<long long>
#define intvv vector<vector<int>>
#define llvv vector<vector<long long>>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
double ans = 0;
for (int i = 1; i <= n; i++) {
double temp = 1.0 / n;
int j = i;
while (j < k) {
j *= 2;
temp /= 2;
}
ans += temp;
}
return printf("%.12f\n", ans);
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define intv vector<v>
#define llv vector<long long>
#define intvv vector<vector<int>>
#define llvv vector<vector<long long>>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
double ans = 0;
for (int i = 1; i <= n; i++) {
double temp = 1.0 / n;
int j = i;
while (j < k) {
j *= 2;
temp /= 2;
}
ans += temp;
}
printf("%.12f\n", ans);
}
| replace | 27 | 28 | 27 | 28 | 15 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
ll binpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
double long ans = 0.0;
for (int i = 1; i <= n; i++) {
if (i >= k)
ans += (1.0) / n;
else {
int t = i;
int count = 1;
while (t < k) {
t = 2 * t;
count *= 2;
}
ans += 1.0 / (n * count);
}
}
cout << fixed << setprecision(10) << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
ll binpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
double long ans = 0.0;
for (int i = 1; i <= n; i++) {
if (i >= k)
ans += (1.0) / n;
else {
int t = i;
int count = 1;
while (t < k) {
t = 2 * t;
count *= 2;
}
ans += 1.0 / (n * count);
}
}
cout << fixed << setprecision(10) << ans << endl;
} | replace | 20 | 24 | 20 | 24 | TLE | |
p03043 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
double sum = 0;
for (int i = 0; i < N; i++) {
double kaku = 1.0 / N;
int now = i;
while (K > now) {
now *= 2;
kaku /= 2;
}
sum += kaku;
}
cout << setprecision(12) << sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
double sum = 0;
for (int i = 1; i <= N; i++) {
double kaku = 1.0 / N;
int now = i;
while (K > now) {
now *= 2;
kaku /= 2;
}
sum += kaku;
}
cout << setprecision(12) << sum << endl;
}
| replace | 7 | 8 | 7 | 8 | TLE | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(), a.end()
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
const long long MOD = 1000000007, INF = 1e17;
#define endl '\n'
#define IOS() \
ios_base::sync_with_stdio(0); \
cin.tie(0)
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;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
//******************************************************************************
int N, K;
signed main() {
// IOS();
cin >> N >> K;
vector<double> d(N, 1.0);
rep(i, 0, N + 1) { d[i + 1] = d[i] / 2.0; }
double ans = 0;
rep(i, 1, N + 1) {
int t = i;
double res = 1.0 / N;
while (t < K) {
res /= 2.0;
t *= 2;
}
ans += res;
}
printf("%.20lf", ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(), a.end()
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
const long long MOD = 1000000007, INF = 1e17;
#define endl '\n'
#define IOS() \
ios_base::sync_with_stdio(0); \
cin.tie(0)
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;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
//******************************************************************************
int N, K;
signed main() {
// IOS();
cin >> N >> K;
double ans = 0;
rep(i, 1, N + 1) {
int t = i;
double res = 1.0 / N;
while (t < K) {
res /= 2.0;
t *= 2;
}
ans += res;
}
printf("%.20lf", ans);
}
| delete | 54 | 56 | 54 | 54 | -6 | malloc(): corrupted top size
|
p03043 | Python | Time Limit Exceeded | from functools import reduce
from operator import mul
def main():
N, K = map(int, input().split())
print(
sum(
[
reduce(mul, [0.5 for j in range(K) if i << j < K], 1 / N)
for i in range(1, N + 1)
]
)
)
return
main()
| from functools import reduce
from operator import mul
def main():
N, K = map(int, input().split())
ans = []
lst = []
for i in range(1, N + 1):
lst.clear()
for j in range(K):
if K <= i << j:
break
lst.append(0.5)
ans.append(reduce(mul, lst, 1 / N))
print(sum(ans))
return
main()
| replace | 6 | 14 | 6 | 16 | TLE | |
p03043 | C++ | Time Limit Exceeded | #include <stdio.h>
int main(void) {
int a, b;
scanf("%d %d", &a, &b);
double ret = 0;
for (int loop = 0; loop <= a; loop++) {
double tmp = 1.0 * a;
int now = loop;
while (now < b) {
now *= 2;
tmp /= 2;
}
ret += tmp;
}
printf("%.12f\n", ret);
return 0;
} | #include <stdio.h>
int main(void) {
int a, b;
scanf("%d %d", &a, &b);
double ret = 0;
for (int loop = 1; loop <= a; loop++) {
double tmp = 1.0 / a;
int now = loop;
while (now < b) {
now *= 2;
tmp /= 2;
}
ret += tmp;
}
printf("%.12f\n", ret);
return 0;
} | replace | 5 | 7 | 5 | 7 | TLE | |
p03043 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
long gcd(long a, long b) {
if (a < 0) {
a = -a;
}
if (b < 0) {
b = -b;
}
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a < b) {
return gcd(a, b % a);
}
return gcd(b, a % b);
}
int main() {
long n, N, K;
long s = 0;
cin >> N >> K;
n = N;
double p = 0;
if (K <= N) {
s = N - K + 1;
n = K - 1;
}
long *r = new long[n];
long rate = 1;
long rmax = 0;
for (long i = n; i > 0; i--) {
while (i * rate < K) {
rate *= 2;
}
r[i - 1] = rate;
rmax = max(rmax, rate);
}
long sum = s * rmax;
long buf = -1;
for (long i = 0; i < n; i++) {
if (i == n - 1 || r[i] != r[i + 1]) {
sum += (i - buf) * (rmax / r[i]);
buf = i;
}
}
s = rmax * N;
long g = gcd(sum, s);
sum /= g;
s /= g;
p = (long double)sum / (long double)s;
printf("%.20lf\n", p);
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
long gcd(long a, long b) {
if (a < 0) {
a = -a;
}
if (b < 0) {
b = -b;
}
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a < b) {
return gcd(a, b % a);
}
return gcd(b, a % b);
}
int main() {
long n, N, K;
long s = 0;
cin >> N >> K;
n = N;
double p = 0;
if (K <= N) {
s = N - K + 1;
n = K - 1;
}
if (n == 0) {
cout << 1 << endl;
return 0;
}
long *r = new long[n];
long rate = 1;
long rmax = 0;
for (long i = n; i > 0; i--) {
while (i * rate < K) {
rate *= 2;
}
r[i - 1] = rate;
rmax = max(rmax, rate);
}
long sum = s * rmax;
long buf = -1;
for (long i = 0; i < n; i++) {
if (i == n - 1 || r[i] != r[i + 1]) {
sum += (i - buf) * (rmax / r[i]);
buf = i;
}
}
s = rmax * N;
long g = gcd(sum, s);
sum /= g;
s /= g;
p = (long double)sum / (long double)s;
printf("%.20lf\n", p);
return 0;
}
| replace | 39 | 40 | 39 | 43 | 0 | |
p03043 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
int main() {
double n, k, ans;
cin >> n >> k;
ans = 0.0;
for (int i = 0; i < n; i++) {
ll point = i;
int p = 0;
while (point < k) {
point *= 2;
p++;
}
ans += (1 / n) * pow(0.50, p);
}
cout << fixed << setprecision(15) << ans << endl;
}
| #include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
int main() {
double n, k, ans;
cin >> n >> k;
ans = 0.0;
for (int i = 1; i <= n; i++) {
ll point = i;
int p = 0;
while (point < k) {
point *= 2;
p++;
}
ans += (1 / n) * pow(0.50, p);
}
cout << fixed << setprecision(15) << ans << endl;
}
| replace | 16 | 17 | 16 | 17 | TLE | |
p03043 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
int n, k;
cin >> n >> k;
double p[n + 1];
for (int i = 1; i <= n; i++) {
p[i] = 1.0;
}
for (int i = 1; i < k; i++) {
int score = i;
while (score < k) {
score *= 2;
p[i] /= 2.0;
}
}
double ans = 0;
for (int i = 1; i <= n; i++) {
ans += p[i];
}
ans /= (double)n;
printf("%.10f\n", ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
int n, k;
cin >> n >> k;
double p[n + 1];
for (int i = 1; i <= n; i++) {
p[i] = 1.0;
}
for (int i = 1; i <= n; i++) {
if (i >= k) {
break;
}
int score = i;
while (score < k) {
score *= 2;
p[i] /= 2.0;
}
}
double ans = 0;
for (int i = 1; i <= n; i++) {
ans += p[i];
}
ans /= (double)n;
printf("%.10f\n", ans);
return 0;
} | replace | 25 | 26 | 25 | 30 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) \
if (cond) \
break
#define ctif(cond) \
if (cond) \
continue
#define retif(cond) \
if (cond) \
return
void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a / b;
a %= b;
swap(a, b);
x0 -= q * x1;
swap(x0, x1);
y0 -= q * y1;
swap(y0, y1);
}
x = x0;
y = y0;
return a;
}
int ctz(uint x) { return __builtin_ctz(x); }
int ctzll(ull x) { return __builtin_ctzll(x); }
int clz(uint x) { return __builtin_clz(x); }
int clzll(ull x) { return __builtin_clzll(x); }
int popcnt(uint x) { return __builtin_popcount(x); }
int popcntll(ull x) { return __builtin_popcountll(x); }
int bsr(uint x) { return 31 ^ clz(x); }
int bsrll(ull x) { return 63 ^ clzll(x); }
#define MX 100016
double dp[MX];
int main() {
// canhazfast();
int n, k;
double ans = 0.0;
scanf("%d%d", &n, &k);
for (int i = k; i <= max(2 * k, n); ++i)
dp[i] = 1.0;
for (int i = k - 1; i > 0; --i)
dp[i] = 0.5 * dp[2 * i];
for (int i = 1; i <= n; ++i)
ans += dp[i];
ans /= n;
printf("%.10lf\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) \
if (cond) \
break
#define ctif(cond) \
if (cond) \
continue
#define retif(cond) \
if (cond) \
return
void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a / b;
a %= b;
swap(a, b);
x0 -= q * x1;
swap(x0, x1);
y0 -= q * y1;
swap(y0, y1);
}
x = x0;
y = y0;
return a;
}
int ctz(uint x) { return __builtin_ctz(x); }
int ctzll(ull x) { return __builtin_ctzll(x); }
int clz(uint x) { return __builtin_clz(x); }
int clzll(ull x) { return __builtin_clzll(x); }
int popcnt(uint x) { return __builtin_popcount(x); }
int popcntll(ull x) { return __builtin_popcountll(x); }
int bsr(uint x) { return 31 ^ clz(x); }
int bsrll(ull x) { return 63 ^ clzll(x); }
#define MX 100016
double dp[2 * MX];
int main() {
// canhazfast();
int n, k;
double ans = 0.0;
scanf("%d%d", &n, &k);
for (int i = k; i <= max(2 * k, n); ++i)
dp[i] = 1.0;
for (int i = k - 1; i > 0; --i)
dp[i] = 0.5 * dp[2 * i];
for (int i = 1; i <= n; ++i)
ans += dp[i];
ans /= n;
printf("%.10lf\n", ans);
return 0;
}
| replace | 78 | 79 | 78 | 79 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
array<int, 17> pow2;
vector<double> ns(N);
int tmp = 1;
for (auto &x : pow2) {
x = tmp;
tmp *= 2;
}
// q(n) は サイコロの目が n-1 の確立
for (int i = 1; i <= N; ++i) {
for (int j = 0;; ++j) {
if (K <= i * pow2.at(j)) {
ns.at(i - 1) = (1.0 / (double)pow2.at(j));
break;
}
}
}
double ans = 0.0;
for (auto i : ns) {
ans += i;
}
ans /= (double)N;
cout << fixed << setprecision(9) << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
array<int, 18> pow2;
vector<double> ns(N);
int tmp = 1;
for (auto &x : pow2) {
x = tmp;
tmp *= 2;
}
// q(n) は サイコロの目が n-1 の確立
for (int i = 1; i <= N; ++i) {
for (int j = 0;; ++j) {
if (K <= i * pow2.at(j)) {
ns.at(i - 1) = (1.0 / (double)pow2.at(j));
break;
}
}
}
double ans = 0.0;
for (auto i : ns) {
ans += i;
}
ans /= (double)N;
cout << fixed << setprecision(9) << ans << endl;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03043 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
ll n, k, pw = 1;
cin >> n >> k;
double p;
p = max((ll)0, n - k + 1);
for (ll i = k;; i = (i + 1) / 2, pw++) {
if ((i + 1) / 2 <= n)
p += (min(i, n + 1) - (i + 1) / 2) * pow(0.5, pw);
if (i == 2)
break;
}
cout << fixed << setprecision(9) << p / n << endl;
return 0;
} | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
ll n, k, pw = 1;
cin >> n >> k;
double p;
p = max((ll)0, n - k + 1);
for (ll i = k;; i = (i + 1) / 2, pw++) {
if ((i + 1) / 2 <= n)
p += (min(i, n + 1) - (i + 1) / 2) * pow(0.5, pw);
if (i == 1)
break;
}
cout << fixed << setprecision(9) << p / n << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p03043 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int devide_by2(int i, int K) {
int count = 0;
while (i < K) {
i *= 2;
count++;
}
return count;
}
double bi(double &ans, int i, double N, int K) {
double count = 1;
for (int j = 0; j < devide_by2(i, K); j++) {
count /= 2;
}
return count * (1 / N);
}
int main() {
double N;
int K;
cin >> N >> K;
cout << fixed << setprecision(11);
double ans = 0;
for (int i = 0; i < N; i++) {
ans += bi(ans, i, N, K);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int devide_by2(int i, int K) {
i++;
int count = 0;
while (i < K) {
i *= 2;
count++;
}
return count;
}
double bi(double &ans, int i, double N, int K) {
double count = 1;
for (int j = 0; j < devide_by2(i, K); j++) {
count /= 2;
}
return count * (1 / N);
}
int main() {
double N;
int K;
cin >> N >> K;
cout << fixed << setprecision(11);
double ans = 0;
for (int i = 0; i < N; i++) {
ans += bi(ans, i, N, K);
}
cout << ans << endl;
}
| insert | 4 | 4 | 4 | 5 | TLE | |
p03043 | Python | Runtime Error | import math
n, k = map(int, input().split())
# for small
score = 0
times = []
for i in range(1, min(n + 1, k)):
times.append(math.ceil(math.log2((k / i))))
bottom_max = times[0]
for t in times:
score += 2 ** (bottom_max - t)
score /= 2 ** (bottom_max) * n
# for big
big = [i for i in range(k, max(k, n + 1))]
score += len(big) / n
print("{:.10f}".format(score))
| import math
n, k = map(int, input().split())
# for small
score = 0
times = []
for i in range(1, min(n + 1, k)):
times.append(math.ceil(math.log2((k / i))))
if len(times):
bottom_max = times[0]
for t in times:
score += 2 ** (bottom_max - t)
score /= 2 ** (bottom_max) * n
# for big
big = [i for i in range(k, max(k, n + 1))]
score += len(big) / n
print("{:.10f}".format(score))
| replace | 9 | 13 | 9 | 15 | 0 | |
p03043 | Python | Runtime Error | import math
N, K = map(int, input().split())
p = 0
for i in range(1, min(K, N + 1)):
print(math.ceil(math.log2(K / i)))
p += 2 ** (-math.ceil(math.log2(K / i)))
p += max(0, N - K + 1)
print(p / N)
| import math
N, K = map(int, input().split())
p = 0
count = 1
while True:
p += (
max(0, min(N + 1, math.ceil(K / 2 ** (count - 1))) - math.ceil(K / 2**count))
* 0.5**count
)
count += 1
if K / 2**count < 0.5:
break
p += max(0, N - K + 1)
print(p / N)
| replace | 5 | 8 | 5 | 14 | 0 | |
p03043 | Python | Runtime Error | def resolve():
N, K = [int(i) for i in input().split()]
import math
ans = 0
for i in range(1, N + 1):
if i < K:
coin = math.ceil(math.log2(K / i))
ans += (1 / N) * ((1 / 2) ** coin)
else:
ans += 1 / N
print(ans)
resolve()
| n, k = map(int, input().split())
ans = 0
for i in range(1, n + 1):
tmp = 1 / n
p = i
while p < k:
p = 2 * p
tmp = tmp / 2
ans += tmp
print(ans)
| replace | 0 | 15 | 0 | 10 | 0 | |
p03043 | Python | Runtime Error | [n, m] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for i in range(m):
idx = a.index(max(a))
a[idx] = int(a[idx] / 2)
print(sum(a))
| [n, k] = [int(i) for i in input().split()]
total = 0
for i in range(1, n + 1):
point = i
prob = 1 / n
while point < k:
point *= 2
prob /= 2
total += prob
print(total)
| replace | 0 | 6 | 0 | 10 | EOFError: EOF when reading a line | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03043/Python/s545196678.py", line 2, in <module>
a = [int(i) for i in input().split()]
EOFError: EOF when reading a line
|
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <class T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/// find_by_order()
/// order_of_key()
template <class T, class U> void maximize(T &x, U y) {
if (x < y)
x = y;
}
template <class T, class U> void minimize(T &x, U y) {
if (x > y)
x = y;
}
template <class T> T Abs(T x) { return (x < (T)0 ? -x : x); }
template <class T> T safe_sqrt(T x) { return sqrt(max(x, (T)0)); }
template <class T, class U, class V> T addmod(T x, U k, V MOD) {
return ((x + k) % MOD + MOD) % MOD;
}
template <class T, class U, class V> T submod(T x, U k, V MOD) {
return ((x - k) % MOD + MOD) % MOD;
}
template <class T, class U, class V> T mul(T x, U y, V MOD) {
return ((x % MOD) * (y % MOD)) % MOD;
}
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define emp emplace_back
#define MASK(i) ((1LL) << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)((c).size())
#define fn "test" /// FILE_NAME_HERE
/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/
namespace task {
void solve() {
int n, k;
double ans = 0.0;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
int j = 0;
while (i * MASK(j) < k) {
++j;
}
ans += pow((double)n, -1) * pow(2, -j);
}
cout << setprecision(20) << fixed;
cout << ans;
}
} // namespace task
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen(fn ".inp", "r", stdin);
freopen(fn ".out", "w", stdout);
#endif // ONLINE_JUDGE
task::solve();
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <class T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/// find_by_order()
/// order_of_key()
template <class T, class U> void maximize(T &x, U y) {
if (x < y)
x = y;
}
template <class T, class U> void minimize(T &x, U y) {
if (x > y)
x = y;
}
template <class T> T Abs(T x) { return (x < (T)0 ? -x : x); }
template <class T> T safe_sqrt(T x) { return sqrt(max(x, (T)0)); }
template <class T, class U, class V> T addmod(T x, U k, V MOD) {
return ((x + k) % MOD + MOD) % MOD;
}
template <class T, class U, class V> T submod(T x, U k, V MOD) {
return ((x - k) % MOD + MOD) % MOD;
}
template <class T, class U, class V> T mul(T x, U y, V MOD) {
return ((x % MOD) * (y % MOD)) % MOD;
}
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define emp emplace_back
#define MASK(i) ((1LL) << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)((c).size())
#define fn "test" /// FILE_NAME_HERE
/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/
namespace task {
void solve() {
int n, k;
double ans = 0.0;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
int j = 0;
while (i * MASK(j) < k) {
++j;
}
ans += pow((double)n, -1) * pow(2, -j);
}
cout << setprecision(20) << fixed;
cout << ans;
}
} // namespace task
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
task::solve();
}
| delete | 71 | 75 | 71 | 71 | 0 | |
p03043 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;
// << fixed << setprecision(10) <<
int main() {
int n, k;
cin >> n >> k;
double ans = 0;
int temp;
int cnt;
for (int i = 1; i <= n; i++) {
temp = i;
cnt = 0;
while (temp < k) {
cnt++;
temp * 2;
}
ans += pow(0.5, cnt);
}
ans /= (double)n;
cout << fixed << setprecision(11) << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;
// << fixed << setprecision(10) <<
int main() {
int n, k;
cin >> n >> k;
double ans = 0;
int temp;
int cnt;
for (int i = 1; i <= n; i++) {
temp = i;
cnt = 0;
for (cnt; temp < k; cnt++) {
temp *= 2;
}
ans += pow(0.5, cnt);
}
ans /= (double)n;
cout << fixed << setprecision(11) << ans << endl;
return 0;
}
| replace | 21 | 24 | 21 | 23 | TLE | |
p03043 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int N, K;
double t[10012];
int main() {
while (cin >> N >> K) {
memset(t, 0, sizeof(t));
for (int i = K; i >= 1; i--) {
if (i >= K) {
t[i] = 1.0;
} else if (i * 2 >= K) {
t[i] = 0.5;
} else {
t[i] = t[i * 2] / 2;
}
}
double sum = 0.0;
for (int i = 1; i <= N; ++i) {
if (i >= K) {
sum += 1.0;
} else {
sum += t[i];
}
}
printf("%.012f\n", sum / N);
}
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int N, K;
double t[100120];
int main() {
while (cin >> N >> K) {
memset(t, 0, sizeof(t));
for (int i = K; i >= 1; i--) {
if (i >= K) {
t[i] = 1.0;
} else if (i * 2 >= K) {
t[i] = 0.5;
} else {
t[i] = t[i * 2] / 2;
}
}
double sum = 0.0;
for (int i = 1; i <= N; ++i) {
if (i >= K) {
sum += 1.0;
} else {
sum += t[i];
}
}
printf("%.012f\n", sum / N);
}
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N, K;
cin >> N >> K;
double ans = 0;
/* 出目がiのとき */
for (int i = 1; i <= N; i++) {
double p = 1. / N;
int num = 0;
for (int point = i; point <= K - 1; point *= 2) {
p *= 1. / 2.;
num++;
}
ans += p;
}
assert(ans < 1);
cout << fixed << setprecision(15) << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N, K;
cin >> N >> K;
double ans = 0;
/* 出目がiのとき */
for (int i = 1; i <= N; i++) {
double p = 1. / N;
int num = 0;
for (int point = i; point <= K - 1; point *= 2) {
p *= 1. / 2.;
num++;
}
ans += p;
}
cout << fixed << setprecision(15) << ans << endl;
return 0;
}
| delete | 18 | 19 | 18 | 18 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;
static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
double n, k;
cin >> n >> k;
vector<double> p;
double tmp = 1.0;
int pos = 1;
while (tmp * tmp < 100005) {
p.pb(tmp);
tmp *= 2;
++pos;
}
p.pb(tmp);
double res = 0.0;
pos = 0;
tmp = n;
while (n > 0) {
while (p[pos] * n < k)
++pos;
res += (1.0 / tmp) * (1.0 / p[pos]);
--n;
}
printf("%.9lf\n", res);
return 0;
}
| #include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;
static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
double n, k;
cin >> n >> k;
vector<double> p;
double tmp = 1.0;
int pos = 1;
while (tmp < 100005) {
p.pb(tmp);
tmp *= 2;
++pos;
}
p.pb(tmp);
double res = 0.0;
pos = 0;
tmp = n;
while (n > 0) {
while (p[pos] * n < k)
++pos;
res += (1.0 / tmp) * (1.0 / p[pos]);
--n;
}
printf("%.9lf\n", res);
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;
int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
double n, k;
cin >> n >> k;
vector<pair<double, int>> pw;
double e = 1.0;
int cnt = 0;
while (e < 100005) {
pw.pb(MP(e, cnt));
e *= 2.0;
++cnt;
}
int pos = n;
int it = 0;
double res = 0;
while (pos >= 1) {
while (pos * pw[it].F < k) {
++it;
}
double tmp = 1.0 / pow(2.0, (double)pw[it].S);
res += tmp * (1 / n);
--pos;
}
printf("%.9lf\n", res);
return 0;
}
| #include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;
int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
double n, k;
cin >> n >> k;
vector<pair<double, int>> pw;
double e = 1.0;
int cnt = 0;
while (e < 100005) {
pw.pb(MP(e, cnt));
e *= 2.0;
++cnt;
}
pw.pb(MP(e, cnt));
int pos = n;
int it = 0;
double res = 0;
while (pos >= 1) {
while (pos * pw[it].F < k) {
++it;
}
double tmp = 1.0 / pow(2.0, (double)pw[it].S);
res += tmp * (1 / n);
--pos;
}
printf("%.9lf\n", res);
return 0;
}
| insert | 39 | 39 | 39 | 41 | 0 | |
p03043 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long inf = 1000000007;
int main() {
int n, k;
cin >> n >> k;
double total = 0;
for (int i = 0; i < n; i++) {
long a = i;
double count = 1.0 / n;
while (a < k) {
a *= 2;
count = count / 2.0;
}
total += count;
}
cout << total << endl;
}
| #include <bits/stdc++.h>
using namespace std;
long inf = 1000000007;
int main() {
int n, k;
cin >> n >> k;
double total = 0;
cout << fixed << setprecision(16);
for (int i = 1; i <= n; i++) {
long a = i;
double count = 1.0 / n;
while (a < k) {
a *= 2;
count = count / 2.0;
}
total += count;
}
cout << total << endl;
}
| replace | 8 | 10 | 8 | 10 | TLE | |
p03043 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define deg(x) cout << x << " "
using ld = long double;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 1e5 + 10;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n, k;
cin >> n >> k;
ll cnt = 0;
vector<ll> pp;
f(i, 1, n + 1) {
if (i < k) {
ll r = ceil(log2(k) - log2(i));
pp.pb(r);
} else {
cnt++;
}
}
if (pp.empty()) {
ld ans = ((ld)cnt) / ((ld)n);
cout << setprecision(14) << fixed << ans << "\n";
return 0;
}
ll ans = 1;
sort(all(pp), greater<ll>());
ll g = (1 << pp[0]);
f(i, 1, (ll)pp.size()) {
ll kk = (1 << pp[i]);
ans += (g / kk);
}
ans = ans + cnt * g;
ll gg = __gcd(n, ans);
n = n / gg;
ans = ans / gg;
gg = __gcd(ans, g);
ans = ans / gg;
g = g / gg;
g = g * n;
ld res = ((ld)ans) / ((ld)g);
cout << setprecision(14) << fixed << res << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define deg(x) cout << x << " "
using ld = long double;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 1e5 + 10;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
ll cnt = 0;
vector<ll> pp;
f(i, 1, n + 1) {
if (i < k) {
ll r = ceil(log2(k) - log2(i));
pp.pb(r);
} else {
cnt++;
}
}
if (pp.empty()) {
ld ans = ((ld)cnt) / ((ld)n);
cout << setprecision(14) << fixed << ans << "\n";
return 0;
}
ll ans = 1;
sort(all(pp), greater<ll>());
ll g = (1 << pp[0]);
f(i, 1, (ll)pp.size()) {
ll kk = (1 << pp[i]);
ans += (g / kk);
}
ans = ans + cnt * g;
ll gg = __gcd(n, ans);
n = n / gg;
ans = ans / gg;
gg = __gcd(ans, g);
ans = ans / gg;
g = g / gg;
g = g * n;
ld res = ((ld)ans) / ((ld)g);
cout << setprecision(14) << fixed << res << "\n";
return 0;
} | delete | 21 | 25 | 21 | 21 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03043 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
/*long long n, k; cin >> n >> k;
double res = 0.0;
for(long long i=1; i<n+1; ++i){
double tmp = 1.0;
long long d = i;
while (d < k) d *= 2, tmp /= 2.0;
res += tmp;
}
res /= n;
cout << fixed << setprecision(10) << res << endl;*/
long long n, k;
cin >> n >> k;
double res = 0.0;
for (long long i = 1; i < n + 1; ++i) {
double tmp = 1.0;
long long d = i;
while (d < k) {
i *= 2;
tmp /= 2.0;
}
res += tmp;
}
res /= n;
cout << fixed << setprecision(15) << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
/*long long n, k; cin >> n >> k;
double res = 0.0;
for(long long i=1; i<n+1; ++i){
double tmp = 1.0;
long long d = i;
while (d < k) d *= 2, tmp /= 2.0;
res += tmp;
}
res /= n;
cout << fixed << setprecision(10) << res << endl;*/
long long n, k;
cin >> n >> k;
double res = 0.0;
for (long long i = 1; i < n + 1; ++i) {
double tmp = 1.0;
long long d = i;
while (d < k) {
d *= 2;
tmp /= 2.0;
}
res += tmp;
}
res /= n;
cout << fixed << setprecision(15) << res << endl;
return 0;
} | replace | 23 | 24 | 23 | 24 | TLE | |
p03043 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
double n, k;
cin >> n >> k;
double ans = 0;
for (int i = 1; i <= n; i++) {
int tmp = i;
double count = 1.0 / n;
while (k > i) {
tmp *= 2;
count /= 2;
}
ans += count;
}
cout << setprecision(15) << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
double n, k;
cin >> n >> k;
double ans = 0;
for (int i = 1; i <= n; i++) {
int tmp = i;
double count = 1.0 / n;
while (k > tmp) {
tmp *= 2;
count /= 2;
}
ans += count;
}
cout << setprecision(15) << ans << endl;
}
| replace | 11 | 12 | 11 | 12 | TLE | |
p03044 | Python | Runtime Error | def dfs(i, d):
# print(i, d)
for j, w in node_array[i]:
if color_array[j] == -1:
color_array[j] = (d + w) % 2
dfs(j, d + w)
N = int(input())
node_array = [[] for i in range(N)]
color_array = [-1] * N
for _ in range(N - 1):
i, j, w = map(int, input().split())
node_array[i - 1].append((j - 1, w))
node_array[j - 1].append((i - 1, w))
color_array[0] = 0
dfs(0, 0)
for i in range(N):
print(color_array[i])
| from sys import setrecursionlimit
setrecursionlimit(10**8)
def dfs(i, d):
# print(i, d)
for j, w in node_array[i]:
if color_array[j] == -1:
color_array[j] = (d + w) % 2
dfs(j, d + w)
N = int(input())
node_array = [[] for i in range(N)]
color_array = [-1] * N
for _ in range(N - 1):
i, j, w = map(int, input().split())
node_array[i - 1].append((j - 1, w))
node_array[j - 1].append((i - 1, w))
color_array[0] = 0
dfs(0, 0)
for i in range(N):
print(color_array[i])
| insert | 0 | 0 | 0 | 5 | 0 | |
p03044 | Python | Runtime Error | class Tree:
WHITE = 0
GRAY = 1
BLACK = 2
def __init__(self, adj):
n = len(adj)
self.adj = adj
self.colors = [self.WHITE] * n
self.depths = [-1] * n
self.depth = 0
def dfs(self, u):
if self.colors[u] == self.BLACK:
return
self.colors[u] = self.GRAY
self.depths[u] = self.depth
for v, w in self.adj[u]:
if self.colors[v] == self.WHITE:
self.depth += w
self.dfs(v)
self.depth -= w
self.colors[u] = self.BLACK
if __name__ == "__main__":
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]
g = [[] for _ in range(n)]
for u, v, w in uvw:
u -= 1
v -= 1
g[u].append((v, w))
g[v].append((u, w))
tree = Tree(g)
tree.dfs(0)
ans = [x % 2 for x in tree.depths]
print(*ans, sep="\n")
| import sys
sys.setrecursionlimit(10**6)
class Tree:
WHITE = 0
GRAY = 1
BLACK = 2
def __init__(self, adj):
n = len(adj)
self.adj = adj
self.colors = [self.WHITE] * n
self.depths = [-1] * n
self.depth = 0
def dfs(self, u):
if self.colors[u] == self.BLACK:
return
self.colors[u] = self.GRAY
self.depths[u] = self.depth
for v, w in self.adj[u]:
if self.colors[v] == self.WHITE:
self.depth += w
self.dfs(v)
self.depth -= w
self.colors[u] = self.BLACK
if __name__ == "__main__":
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]
g = [[] for _ in range(n)]
for u, v, w in uvw:
u -= 1
v -= 1
g[u].append((v, w))
g[v].append((u, w))
tree = Tree(g)
tree.dfs(0)
ans = [x % 2 for x in tree.depths]
print(*ans, sep="\n")
| insert | 0 | 0 | 0 | 5 | 0 | |
p03044 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
vector<int> dir;
void dfs(const Graph &G, int v, int p, int cur) {
dir[v] = cur;
for (auto e : G[v]) {
if (e.first == p)
continue; // e.first(nv)が親pだったらダメ
if (e.second % 2)
dfs(G, e.first, v, 1 - cur);
else
dfs(G, e.first, v, cur);
}
}
int main() {
int N;
cin >> N;
Graph G(N);
G.assign(N, vector<Edge>());
for (int i = 0; i < N - 1; ++i) {
int a, b, w;
--a, --b;
G[a].push_back(Edge(b, w));
G[b].push_back(Edge(a, w));
}
dir.assign(N, 0);
dfs(G, 0, -1, 0);
for (int i = 0; i < N; ++i)
cout << dir[i] << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
vector<int> dir;
void dfs(const Graph &G, int v, int p, int cur) {
dir[v] = cur;
for (auto e : G[v]) {
if (e.first == p)
continue; // e.first(nv)が親pだったらダメ
if (e.second % 2)
dfs(G, e.first, v, 1 - cur);
else
dfs(G, e.first, v, cur);
}
}
int main() {
int N;
cin >> N;
Graph G(N);
G.assign(N, vector<Edge>());
for (int i = 0; i < N - 1; ++i) {
int a, b, w;
cin >> a >> b >> w;
--a, --b;
G[a].push_back(Edge(b, w));
G[b].push_back(Edge(a, w));
}
dir.assign(N, 0);
dfs(G, 0, -1, 0);
for (int i = 0; i < N; ++i)
cout << dir[i] << endl;
}
| insert | 29 | 29 | 29 | 30 | -11 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
vector<vector<int>> vec(100001, vector<int>());
vector<bool> ans(100001, true);
vector<bool> used(100001, false);
void func(int idx) {
used[idx] = true;
// cout << "idx : " << idx << endl;
for (int i = 0; i < vec[idx].size(); i += 2) {
if (used[vec[idx][i]]) {
continue;
}
if (vec[idx][i + 1] % 2) {
ans[vec[idx][i]] = !ans[idx];
} else {
ans[vec[idx][i + 1]] = ans[idx];
}
func(vec[idx][i]);
}
}
int main() {
int n, u, v, w;
cin >> n;
for (int i = 0; i < n - 1; i++) {
cin >> u >> v >> w;
vec[u].push_back(v);
vec[u].push_back(w);
vec[v].push_back(u);
vec[v].push_back(w);
}
func(1);
for (int i = 0; i < n; i++) {
cout << ((ans[i + 1]) ? 1 : 0) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
vector<vector<int>> vec(100001, vector<int>());
vector<bool> ans(100001, true);
vector<bool> used(100001, false);
void func(int idx) {
used[idx] = true;
// cout << "idx : " << idx << endl;
for (int i = 0; i < vec[idx].size(); i += 2) {
if (used[vec[idx][i]]) {
continue;
}
if (vec[idx][i + 1] % 2) {
ans[vec[idx][i]] = !ans[idx];
} else {
ans[vec[idx][i]] = ans[idx];
}
func(vec[idx][i]);
}
}
int main() {
int n, u, v, w;
cin >> n;
for (int i = 0; i < n - 1; i++) {
cin >> u >> v >> w;
vec[u].push_back(v);
vec[u].push_back(w);
vec[v].push_back(u);
vec[v].push_back(w);
}
func(1);
for (int i = 0; i < n; i++) {
cout << ((ans[i + 1]) ? 1 : 0) << endl;
}
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03044 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> to(N);
vector<vector<int>> cost(N);
for (int i = 1; i < N; i++) {
int a, b, w;
cin >> a >> b >> w;
to[a].push_back(b);
cost[a].push_back(w);
to[b].push_back(a);
cost[b].push_back(w);
}
int cnt = 0;
vector<int> ans(N, -1);
queue<int> Q;
Q.push(0);
ans[0] = 0;
while (!Q.empty()) {
int p = Q.front();
Q.pop();
for (int i = 0; i < to[p].size(); i++) {
int u = to[p][i];
if (ans[u] != -1) {
continue;
}
ans[u] = (ans[p] + cost[p][i]) % 2;
Q.push(u);
}
}
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> to(N);
vector<vector<int>> cost(N);
for (int i = 1; i < N; i++) {
int a, b, w;
cin >> a >> b >> w;
a--;
b--;
to[a].push_back(b);
cost[a].push_back(w);
to[b].push_back(a);
cost[b].push_back(w);
}
int cnt = 0;
vector<int> ans(N, -1);
queue<int> Q;
Q.push(0);
ans[0] = 0;
while (!Q.empty()) {
int p = Q.front();
Q.pop();
for (int i = 0; i < to[p].size(); i++) {
int u = to[p][i];
if (ans[u] != -1) {
continue;
}
ans[u] = (ans[p] + cost[p][i]) % 2;
Q.push(u);
}
}
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
} | insert | 15 | 15 | 15 | 17 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03044 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int n;
vector<vector<int>> to(n + 100);
vector<vector<int>> cost(n + 100);
int main() {
/* 入力受け取り */
cin >> n;
for (int i = 0; i < n - 1; ++i) {
int a, b, w;
cin >> a >> b >> w;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
cost[a].push_back(w);
cost[b].push_back(w);
}
/* BFS */
queue<int> que;
vector<int> ans(n, -1);
que.push(0);
ans[0] = 0;
// キューが0になるまでループ
while (que.size()) {
// 先頭のキューを取ってくる
int p = que.front();
que.pop();
// 先頭のキューに繋がっているノードを探索
for (int i = 0; i < to[p].size(); ++i) {
int u = to[p][i];
int w = cost[p][i];
if (ans[u] != -1)
continue;
ans[u] = (ans[p] + w) % 2;
que.push(u);
}
}
for (int i = 0; i < n; ++i)
cout << ans[i] << endl;
return 0;
}
| #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int n;
vector<vector<int>> to(n + 1000000);
vector<vector<int>> cost(n + 1000000);
int main() {
/* 入力受け取り */
cin >> n;
for (int i = 0; i < n - 1; ++i) {
int a, b, w;
cin >> a >> b >> w;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
cost[a].push_back(w);
cost[b].push_back(w);
}
/* BFS */
queue<int> que;
vector<int> ans(n, -1);
que.push(0);
ans[0] = 0;
// キューが0になるまでループ
while (que.size()) {
// 先頭のキューを取ってくる
int p = que.front();
que.pop();
// 先頭のキューに繋がっているノードを探索
for (int i = 0; i < to[p].size(); ++i) {
int u = to[p][i];
int w = cost[p][i];
if (ans[u] != -1)
continue;
ans[u] = (ans[p] + w) % 2;
que.push(u);
}
}
for (int i = 0; i < n; ++i)
cout << ans[i] << endl;
return 0;
}
| replace | 5 | 7 | 5 | 7 | 0 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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;
}
using P = pair<long long, long long>;
#define rep(i, n) for (long long i = 0; i < (long long)n; i++)
#define FOR(i, a, b) for (long long i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define onBoard(y, x) (y >= 0 && y < h && x >= 0 && x < w)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int, int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(), x.end(), 0)
#define MAX(x) *max_element(x.begin(), x.end())
#define MIN(x) *min_element(x.begin(), x.end())
#define couty cout << "Yes" << endl
#define coutn cout << "No" << endl
#define coutY cout << "YES" << endl
#define coutN cout << "NO" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
#define YN(x) cout << (x ? "YES" : "NO") << endl
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
const long long INF = 1e12;
const long long MOD = 1e9 + 7;
struct edge {
int to, cost;
};
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int n;
cin >> n;
vector<vector<edge>> g(n);
vector<int> color(n, -1);
rep(i, n - 1) {
int u, v, w;
// cin >> u >> v >> w;
scanf("%lld%lld%lld", &u, &v, &w);
u--;
v--;
g[u].PB(edge{v, w});
g[v].PB(edge{u, w});
}
color[0] = 0;
queue<int> que;
que.push(0);
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto nv : g[v]) {
if (color[nv.to] != -1)
continue;
if (nv.cost % 2 == 0) {
color[nv.to] = color[v];
que.push(nv.to);
} else {
color[nv.to] = color[v] ^ 1;
que.push(nv.to);
}
}
}
rep(i, n) cout << color[i] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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;
}
using P = pair<long long, long long>;
#define rep(i, n) for (long long i = 0; i < (long long)n; i++)
#define FOR(i, a, b) for (long long i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define onBoard(y, x) (y >= 0 && y < h && x >= 0 && x < w)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int, int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(), x.end(), 0)
#define MAX(x) *max_element(x.begin(), x.end())
#define MIN(x) *min_element(x.begin(), x.end())
#define couty cout << "Yes" << endl
#define coutn cout << "No" << endl
#define coutY cout << "YES" << endl
#define coutN cout << "NO" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
#define YN(x) cout << (x ? "YES" : "NO") << endl
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
const long long INF = 1e12;
const long long MOD = 1e9 + 7;
struct edge {
int to, cost;
};
signed main() {
// cin.tie(nullptr);
// ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int n;
cin >> n;
vector<vector<edge>> g(n);
vector<int> color(n, -1);
rep(i, n - 1) {
int u, v, w;
// cin >> u >> v >> w;
scanf("%lld%lld%lld", &u, &v, &w);
u--;
v--;
g[u].PB(edge{v, w});
g[v].PB(edge{u, w});
}
color[0] = 0;
queue<int> que;
que.push(0);
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto nv : g[v]) {
if (color[nv.to] != -1)
continue;
if (nv.cost % 2 == 0) {
color[nv.to] = color[v];
que.push(nv.to);
} else {
color[nv.to] = color[v] ^ 1;
que.push(nv.to);
}
}
}
rep(i, n) cout << color[i] << endl;
} | replace | 57 | 59 | 57 | 59 | -11 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using multiInt = boost::multiprecision::cpp_int;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ll MOD = (ll)(1e9 + 7);
const double PI = acos(-1.0);
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) \
for (auto a_ : x_) \
cerr << a_ << " "; \
cerr << endl;
#define dbg3(x_, sx_) \
rep(i, sx_) cerr << x_[i] << " "; \
cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; }
//------------------------------------------------------
int ans[100010];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pii> E[100010];
rep(i, n) ans[i] = -1;
rep(i, n - 1) {
int u, v, w;
cin >> u >> v >> w;
u--, v--;
E[u].push_back(MP(v, w % 2));
E[w].push_back(MP(u, w % 2));
}
queue<int> que;
que.push(0);
ans[0] = 0;
while (!que.empty()) {
int now = que.front();
que.pop();
for (auto e : E[now]) {
if (ans[e.first] == -1) {
que.push(e.first);
ans[e.first] = (ans[now] ^ e.second);
}
}
}
rep(i, n) cout << ans[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using multiInt = boost::multiprecision::cpp_int;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ll MOD = (ll)(1e9 + 7);
const double PI = acos(-1.0);
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) \
for (auto a_ : x_) \
cerr << a_ << " "; \
cerr << endl;
#define dbg3(x_, sx_) \
rep(i, sx_) cerr << x_[i] << " "; \
cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; }
//------------------------------------------------------
int ans[100010];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pii> E[100010];
rep(i, n) ans[i] = -1;
rep(i, n - 1) {
int u, v, w;
cin >> u >> v >> w;
u--, v--;
E[u].push_back(MP(v, w % 2));
E[v].push_back(MP(u, w % 2));
}
queue<int> que;
que.push(0);
ans[0] = 0;
while (!que.empty()) {
int now = que.front();
que.pop();
for (auto e : E[now]) {
if (ans[e.first] == -1) {
que.push(e.first);
ans[e.first] = (ans[now] ^ e.second);
}
}
}
rep(i, n) cout << ans[i] << endl;
return 0;
}
| replace | 58 | 59 | 58 | 59 | 0 | |
p03044 | Python | Time Limit Exceeded | N = int(input())
node_array = [list(map(int, input().split())) for i in range(N - 1)]
# print(node_array)
tree_num_array = [-1] * N
# print(tree_num_array)
tree_num_max = -1
tree = {}
last_tree_num = -1
for node in node_array:
# print(tree)
i, j, w = node
i = i - 1
j = j - 1
if tree_num_array[i] == -1 and tree_num_array[j] == -1:
# print(i, j, "added")
tree_num_max += 1
tree[tree_num_max] = {i: 0, j: w}
tree_num_array[i] = tree_num_max
tree_num_array[j] = tree_num_max
last_tree_num = tree_num_max
continue
elif tree_num_array[i] == -1:
# print(i, "added")
tree_num_added = tree_num_array[j]
tree[tree_num_added][i] = tree[tree_num_added][j] + w
tree_num_array[i] = tree_num_added
last_tree_num = tree_num_added
elif tree_num_array[j] == -1:
# print(j, "added")
tree_num_added = tree_num_array[i]
tree[tree_num_added][j] = tree[tree_num_added][i] + w
tree_num_array[j] = tree_num_added
last_tree_num = tree_num_added
else:
tree_num_added = tree_num_array[i]
tree_num_united = tree_num_array[j]
# print(tree_num_added, tree_num_united, "united")
tree_value_i = tree[tree_num_added][i]
tree_value_j = tree[tree_num_united][j]
for key, value in tree[tree_num_united].items():
tree[tree_num_added][key] = tree_value_i + w + abs(value - tree_value_j)
tree_num_array[int(key)] = tree_num_added
last_tree_num = tree_num_added
# print(tree)
ans_dict = sorted(tree[last_tree_num].items(), key=lambda x: int(x[0]))
# print(ans_dict)
for distance in ans_dict:
print(distance[1] % 2)
| N = int(input())
node_array = [list(map(int, input().split())) for i in range(N - 1)]
# print(node_array)
tree_num_array = [-1] * N
# print(tree_num_array)
tree_num_max = -1
tree = {}
last_tree_num = -1
for node in node_array:
# print(tree)
i, j, w = node
i = i - 1
j = j - 1
if tree_num_array[i] == -1 and tree_num_array[j] == -1:
# print(i, j, "added")
tree_num_max += 1
tree[tree_num_max] = {i: 0, j: w}
tree_num_array[i] = tree_num_max
tree_num_array[j] = tree_num_max
last_tree_num = tree_num_max
continue
elif tree_num_array[i] == -1:
# print(i, "added")
tree_num_added = tree_num_array[j]
tree[tree_num_added][i] = tree[tree_num_added][j] + w
tree_num_array[i] = tree_num_added
last_tree_num = tree_num_added
elif tree_num_array[j] == -1:
# print(j, "added")
tree_num_added = tree_num_array[i]
tree[tree_num_added][j] = tree[tree_num_added][i] + w
tree_num_array[j] = tree_num_added
last_tree_num = tree_num_added
else:
tree_num_i = tree_num_array[i]
tree_num_j = tree_num_array[j]
# print(tree_num_i, tree_num_j, "unite")
if len(tree[tree_num_i]) > len(tree[tree_num_j]):
tree_main_num = tree_num_i
tree_main_value = tree[tree_main_num][i]
tree_sub_num = tree_num_j
tree_sub_value = tree[tree_sub_num][j]
else:
tree_main_num = tree_num_j
tree_main_value = tree[tree_main_num][j]
tree_sub_num = tree_num_i
tree_sub_value = tree[tree_sub_num][i]
for key, value in tree[tree_sub_num].items():
tree[tree_main_num][key] = tree_main_value + w + abs(value - tree_sub_value)
tree_num_array[int(key)] = tree_main_num
last_tree_num = tree_main_num
# print(tree)
ans_dict = sorted(tree[last_tree_num].items(), key=lambda x: int(x[0]))
# print(ans_dict)
for distance in ans_dict:
print(distance[1] % 2)
| replace | 35 | 44 | 35 | 53 | TLE | |
p03044 | C++ | Runtime Error | #include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)
int main(int argc, const char *argv[]) {
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<vector<pil>> G(N, vector<pil>(N));
for (int n = 1; n <= N - 1; ++n) {
int u, v;
ll w;
cin >> u >> v >> w;
--u;
--v;
G[u].emplace_back(v, w);
G[v].emplace_back(u, w);
}
vector<ll> D(N, INF);
vector<int> Used(N, 0);
D[0] = 0;
Used[0] = 1;
queue<int> Que;
Que.push(0);
while (!Que.empty()) {
int Temp = Que.front();
Que.pop();
for (auto e : G[Temp]) {
int u = e.first;
ll w = e.second;
if (Used[u])
continue;
Used[u] = 1;
D[u] = D[Temp] + w;
Que.push(u);
}
}
for (int n = 0; n < N; ++n) {
cout << D[n] % 2 << '\n';
}
return 0;
}
| #include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)
int main(int argc, const char *argv[]) {
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<vector<pil>> G(N);
for (int n = 1; n <= N - 1; ++n) {
int u, v;
ll w;
cin >> u >> v >> w;
--u;
--v;
G[u].emplace_back(v, w);
G[v].emplace_back(u, w);
}
vector<ll> D(N, INF);
vector<int> Used(N, 0);
D[0] = 0;
Used[0] = 1;
queue<int> Que;
Que.push(0);
while (!Que.empty()) {
int Temp = Que.front();
Que.pop();
for (auto e : G[Temp]) {
int u = e.first;
ll w = e.second;
if (Used[u])
continue;
Used[u] = 1;
D[u] = D[Temp] + w;
Que.push(u);
}
}
for (int n = 0; n < N; ++n) {
cout << D[n] % 2 << '\n';
}
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int col[100000];
struct edge {
int to;
ll w;
};
vector<edge> G[100000];
void dfs(int u, bool c) {
col[u] = c;
for (int i = 0; i < G[u].size(); i++) {
if (col[G[u][i].to] != -1)
continue;
ll dif;
dif = G[u][i].w;
if (dif % 2)
dfs(G[u][i].to, !c);
else
dfs(G[u][i].to, c);
}
}
int main() {
fill(col, col + 100000, -1);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int u, v;
ll w;
cin >> u >> v >> w;
u--, v--;
G[u].push_back({v, w});
G[v].push_back({u, w});
}
dfs(0, 0);
for (int i = 0; i < n; i++) {
cout << col[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int col[100000];
struct edge {
int to;
ll w;
};
vector<edge> G[100000];
void dfs(int u, bool c) {
col[u] = c;
for (int i = 0; i < G[u].size(); i++) {
if (col[G[u][i].to] != -1)
continue;
ll dif;
dif = G[u][i].w;
if (dif % 2)
dfs(G[u][i].to, !c);
else
dfs(G[u][i].to, c);
}
}
int main() {
fill(col, col + 100000, -1);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
ll w;
cin >> u >> v >> w;
u--, v--;
G[u].push_back({v, w});
G[v].push_back({u, w});
}
dfs(0, 0);
for (int i = 0; i < n; i++) {
cout << col[i] << endl;
}
return 0;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p03044 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
using int_t = int64_t;
struct edge_t {
int_t to, len;
edge_t(int_t t, int_t l) : to(t), len(l) {}
};
void dfs(const vector<vector<edge_t>> &E, vector<int> &color, int s, int c) {
color[s] = c;
for (auto &next : E[s]) {
if (color[next.to] != -1)
continue;
dfs(E, color, next.to, (next.len % 2 == 0) ? c : !c);
}
}
int main(void) {
int N;
cin >> N;
vector<vector<edge_t>> E(N * N);
vector<int> color(N, -1);
for (int i = 0; i < N - 1; i++) {
int_t from;
cin >> from;
int_t to;
cin >> to;
int_t len;
cin >> len;
from--, to--;
E[from].emplace_back(to, len);
E[to].emplace_back(from, len);
}
for (int i = 0; i < N; i++) {
if (color[i] == -1) {
dfs(E, color, i, 0);
}
}
for (auto c : color) {
cout << c << endl;
}
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
using int_t = int64_t;
struct edge_t {
int_t to, len;
edge_t(int_t t, int_t l) : to(t), len(l) {}
};
void dfs(const vector<vector<edge_t>> &E, vector<int> &color, int s, int c) {
color[s] = c;
for (auto &next : E[s]) {
if (color[next.to] != -1)
continue;
dfs(E, color, next.to, (next.len % 2 == 0) ? c : !c);
}
}
int main(void) {
int N;
cin >> N;
vector<vector<edge_t>> E(N);
vector<int> color(N, -1);
for (int i = 0; i < N - 1; i++) {
int_t from;
cin >> from;
int_t to;
cin >> to;
int_t len;
cin >> len;
from--, to--;
E[from].emplace_back(to, len);
E[to].emplace_back(from, len);
}
for (int i = 0; i < N; i++) {
if (color[i] == -1) {
dfs(E, color, i, 0);
}
}
for (auto c : color) {
cout << c << endl;
}
return 0;
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p03044 | C++ | Runtime Error | // D - Even Relation
#include <bits/stdc++.h>
using namespace std;
void dfs(const vector<vector<pair<int, int>>> &g, int u, int c, vector<int> &a,
vector<int> &vi) {
if (vi[u])
return;
vi[u] = 1;
a[u] = c;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i].first;
if (!vi[v])
dfs(g, v, g[u][i].second ? c ^ 1 : c, a, vi);
}
}
int main(int argc, char *argv[]) {
int n;
cin >> n;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < n; i++) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
g[u].push_back(make_pair(v, w % 2));
g[v].push_back(make_pair(u, w % 2));
}
vector<int> a(n), vi(n);
dfs(g, 0, 0, a, vi);
for (int i = 0; i < n; i++)
cout << a[i] << endl;
return 0;
}
| // D - Even Relation
#include <bits/stdc++.h>
using namespace std;
void dfs(const vector<vector<pair<int, int>>> &g, int u, int c, vector<int> &a,
vector<int> &vi) {
if (vi[u])
return;
vi[u] = 1;
a[u] = c;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i].first;
if (!vi[v])
dfs(g, v, g[u][i].second ? c ^ 1 : c, a, vi);
}
}
int main(int argc, char *argv[]) {
int n;
cin >> n;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < n - 1; i++) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
g[u].push_back(make_pair(v, w % 2));
g[v].push_back(make_pair(u, w % 2));
}
vector<int> a(n), vi(n);
dfs(g, 0, 0, a, vi);
for (int i = 0; i < n; i++)
cout << a[i] << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define N 10010
#define ll long long
const ll mod = 1e9 + 7;
struct node {
int v, w;
};
vector<node> g[N];
int vis[N];
void dfs(int x) {
int sz = g[x].size();
for (int i = 0; i < sz; i++) {
int v = g[x][i].v, w = g[x][i].w;
if (vis[v] != -1)
continue;
if (w & 1)
vis[v] = 1 ^ vis[x];
else
vis[v] = vis[x];
dfs(v);
}
}
int main() {
memset(vis, -1, sizeof vis);
int n, u, v, w;
scanf("%d", &n);
for (int i = 1; i < n; i++) {
scanf("%d%d%d", &u, &v, &w);
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vis[1] = 0;
dfs(1);
for (int i = 1; i <= n; i++)
printf("%d\n", vis[i]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
const ll mod = 1e9 + 7;
struct node {
int v, w;
};
vector<node> g[N];
int vis[N];
void dfs(int x) {
int sz = g[x].size();
for (int i = 0; i < sz; i++) {
int v = g[x][i].v, w = g[x][i].w;
if (vis[v] != -1)
continue;
if (w & 1)
vis[v] = 1 ^ vis[x];
else
vis[v] = vis[x];
dfs(v);
}
}
int main() {
memset(vis, -1, sizeof vis);
int n, u, v, w;
scanf("%d", &n);
for (int i = 1; i < n; i++) {
scanf("%d%d%d", &u, &v, &w);
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vis[1] = 0;
dfs(1);
for (int i = 1; i <= n; i++)
printf("%d\n", vis[i]);
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03044 | C++ | Runtime Error | #include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
// vector<pair<int, int> > G[10001];
map<int, vector<pair<int, int>>> G;
for (int i = 0; i < N - 1; i++) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
w %= 2;
G[u].push_back(make_pair(v, w));
G[v].push_back(make_pair(u, w));
}
queue<pair<int, int>> Q;
Q.push(make_pair(0, 0));
int color[10001] = {0};
int checked[10001] = {0};
while (Q.size()) {
pair<int, int> p = Q.front();
Q.pop();
checked[p.first]++;
if (p.second % 2)
color[p.first] = 1;
for (int i = 0; i < G[p.first].size(); i++) {
pair<int, int> n = G[p.first][i];
if (checked[n.first]) {
continue;
}
Q.push(make_pair(n.first, p.second + n.second));
}
}
for (int i = 0; i < N; i++) {
cout << color[i] << endl;
}
return 0;
}
| #include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
// vector<pair<int, int> > G[10001];
map<int, vector<pair<int, int>>> G;
for (int i = 0; i < N - 1; i++) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
w %= 2;
G[u].push_back(make_pair(v, w));
G[v].push_back(make_pair(u, w));
}
queue<pair<int, int>> Q;
Q.push(make_pair(0, 0));
int color[100001] = {0};
int checked[100001] = {0};
while (Q.size()) {
pair<int, int> p = Q.front();
Q.pop();
checked[p.first]++;
if (p.second % 2)
color[p.first] = 1;
for (int i = 0; i < G[p.first].size(); i++) {
pair<int, int> n = G[p.first][i];
if (checked[n.first]) {
continue;
}
Q.push(make_pair(n.first, p.second + n.second));
}
}
for (int i = 0; i < N; i++) {
cout << color[i] << endl;
}
return 0;
}
| replace | 21 | 23 | 21 | 23 | 0 | |
p03044 | Python | Runtime Error | def dfs(u):
for v, w in edge[u]:
if trail[v] is None:
trail[v] = (trail[u] + w) % 2
dfs(v)
N = int(input())
trail = [None] * N
edge = [[] for _ in range(N)]
for i in range(N - 1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
w %= 2
edge[u].append((v, w))
edge[v].append((u, w))
trail[0] = 0
dfs(0)
for t in trail:
print(t)
| import sys
sys.setrecursionlimit(10**6)
def dfs(u):
for v, w in edge[u]:
if trail[v] is None:
trail[v] = (trail[u] + w) % 2
dfs(v)
N = int(input())
trail = [None] * N
edge = [[] for _ in range(N)]
for i in range(N - 1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
w %= 2
edge[u].append((v, w))
edge[v].append((u, w))
trail[0] = 0
dfs(0)
for t in trail:
print(t)
| insert | 0 | 0 | 0 | 5 | 0 | |
p03044 | Python | Runtime Error | import sys
from io import StringIO
import unittest
import os
sys.setrecursionlimit(9999999999)
def dfs(now, edge, colors):
# 枝を全て調査
for i in edge[now]:
# 色を設定済みなら何もしない
if not colors[i[0]] == -1:
continue
# 色の設定
# 親子の距離%2(偶数0:奇数:1) + 親(偶数0:奇数:1) の余りを子に設定(偶数なら0 奇数なら1を設定できるロジック)
colors[i[0]] = (i[1] % 2 + colors[now]) % 2
# 再帰処理
dfs(i[0], edge, colors)
# 実装を行う関数
def resolve():
n = int(input())
uvw = [list(map(int, input().split())) for i in range(n - 1)]
edge = [[] for i in range(n + 1)]
# 例:edge[0] = [[1, 100][2, 300]]
# 点0は点1と距離100、点2と距離300でつながっている。
for i in uvw:
edge[i[0]].append([i[1], i[2]])
edge[i[1]].append([i[0], i[2]])
# -1は「未設定」の意味
colors = [-1 for i in range(n + 1)]
# 初期(適当な点を黒に塗る)
colors[1] = 1
dfs(1, edge, colors)
for i in range(1, len(colors)):
print(colors[i])
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3
1 2 2
2 3 1"""
output = """0
0
1"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """5
2 5 2
2 3 10
1 3 8
3 4 2"""
output = """1
0
1
0
1"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| import sys
from io import StringIO
import unittest
import os
sys.setrecursionlimit(999999999)
def dfs(now, edge, colors):
# 枝を全て調査
for i in edge[now]:
# 色を設定済みなら何もしない
if not colors[i[0]] == -1:
continue
# 色の設定
# 親子の距離%2(偶数0:奇数:1) + 親(偶数0:奇数:1) の余りを子に設定(偶数なら0 奇数なら1を設定できるロジック)
colors[i[0]] = (i[1] % 2 + colors[now]) % 2
# 再帰処理
dfs(i[0], edge, colors)
# 実装を行う関数
def resolve():
n = int(input())
uvw = [list(map(int, input().split())) for i in range(n - 1)]
edge = [[] for i in range(n + 1)]
# 例:edge[0] = [[1, 100][2, 300]]
# 点0は点1と距離100、点2と距離300でつながっている。
for i in uvw:
edge[i[0]].append([i[1], i[2]])
edge[i[1]].append([i[0], i[2]])
# -1は「未設定」の意味
colors = [-1 for i in range(n + 1)]
# 初期(適当な点を黒に塗る)
colors[1] = 1
dfs(1, edge, colors)
for i in range(1, len(colors)):
print(colors[i])
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3
1 2 2
2 3 1"""
output = """0
0
1"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """5
2 5 2
2 3 10
1 3 8
3 4 2"""
output = """1
0
1
0
1"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| replace | 5 | 6 | 5 | 6 | OverflowError: Python int too large to convert to C int | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03044/Python/s708960220.py", line 6, in <module>
sys.setrecursionlimit(9999999999)
OverflowError: Python int too large to convert to C int
|
p03044 | Python | Runtime Error | def rec(edges, nodes, cp, cdistance, visited):
if not visited[cp]:
visited[cp] = True
nodes[cp] = cdistance % 2 == 0
if edges[cp]:
for v, w in edges[cp]:
rec(edges, nodes, v, cdistance + w, visited)
def main():
N = int(input())
nodes = [False] * N
visited = [False] * N
edges = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = map(int, input().split())
edges[u - 1].append((v - 1, w))
edges[v - 1].append((u - 1, w))
rec(edges, nodes, 0, 0, visited)
for n in nodes:
print(0 if n else 1)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**9)
def rec(edges, nodes, cp, cdistance, visited):
if not visited[cp]:
visited[cp] = True
nodes[cp] = cdistance % 2 == 0
if edges[cp]:
for v, w in edges[cp]:
rec(edges, nodes, v, cdistance + w, visited)
def main():
N = int(input())
nodes = [False] * N
visited = [False] * N
edges = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = map(int, input().split())
edges[u - 1].append((v - 1, w))
edges[v - 1].append((u - 1, w))
rec(edges, nodes, 0, 0, visited)
for n in nodes:
print(0 if n else 1)
if __name__ == "__main__":
main()
| insert | 0 | 0 | 0 | 5 | 0 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long lld;
vector<pair<lld, lld>> G[55555];
lld dis[555555];
void dfs(lld u, lld par = -1) {
for (lld i = 0; i < G[u].size(); i++) {
lld to = G[u][i].first;
lld w = G[u][i].second;
if (to != par) {
dis[to] += dis[u] + w;
dfs(to, u);
}
}
return;
}
int main() {
std::ios::sync_with_stdio(false);
lld n;
cin >> n;
for (lld i = 0; i < n - 1; i++) {
lld u, v, w;
cin >> u >> v >> w;
G[u].push_back(make_pair(v, w));
G[v].push_back(make_pair(u, w));
}
dfs(1);
vector<lld> color(n + 1, 0);
for (lld i = 1; i <= n; i++) {
if (dis[i] % 2) {
color[i] = 0;
} else {
color[i] = 1;
}
}
for (lld i = 1; i <= n; i++) {
cout << color[i] << "\n";
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long lld;
vector<pair<lld, lld>> G[555555];
lld dis[555555];
void dfs(lld u, lld par = -1) {
for (lld i = 0; i < G[u].size(); i++) {
lld to = G[u][i].first;
lld w = G[u][i].second;
if (to != par) {
dis[to] += dis[u] + w;
dfs(to, u);
}
}
return;
}
int main() {
std::ios::sync_with_stdio(false);
lld n;
cin >> n;
for (lld i = 0; i < n - 1; i++) {
lld u, v, w;
cin >> u >> v >> w;
G[u].push_back(make_pair(v, w));
G[v].push_back(make_pair(u, w));
}
dfs(1);
vector<lld> color(n + 1, 0);
for (lld i = 1; i <= n; i++) {
if (dis[i] % 2) {
color[i] = 0;
} else {
color[i] = 1;
}
}
for (lld i = 1; i <= n; i++) {
cout << color[i] << "\n";
}
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
struct edge {
ll v, w;
};
int main() {
ll n;
cin >> n;
vector<vector<edge>> adj(n);
ll a, b, c;
rep(i, n) {
cin >> a >> b >> c;
a--, b--;
adj[a].push_back((edge){b, c});
adj[b].push_back((edge){a, c});
}
vector<ll> col(n, -1);
queue<ll> q;
q.push(0);
col[0] = 0;
while (!q.empty()) {
ll now = q.front();
q.pop();
rep(i, adj[now].size()) {
ll nv = adj[now][i].v, nw = adj[now][i].w;
if (col[nv] == -1) {
if (nw % 2)
col[nv] = !(bool)col[now];
else
col[nv] = col[now];
q.push(nv);
}
}
}
rep(i, n) cout << col[i] << endl;
return 0;
} | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
struct edge {
ll v, w;
};
int main() {
ll n;
cin >> n;
vector<vector<edge>> adj(n);
ll a, b, c;
rep(i, n - 1) {
cin >> a >> b >> c;
a--, b--;
adj[a].push_back((edge){b, c});
adj[b].push_back((edge){a, c});
}
vector<ll> col(n, -1);
queue<ll> q;
q.push(0);
col[0] = 0;
while (!q.empty()) {
ll now = q.front();
q.pop();
rep(i, adj[now].size()) {
ll nv = adj[now][i].v, nw = adj[now][i].w;
if (col[nv] == -1) {
if (nw % 2)
col[nv] = !(bool)col[now];
else
col[nv] = col[now];
q.push(nv);
}
}
}
rep(i, n) cout << col[i] << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p03044 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int n;
int d[100005], cc[100005];
vector<pair<int, int>> edge[100005];
void dfs(int x, int prev) {
for (int i = 0; i < edge[x].size(); i++) {
int y = edge[x][i].first;
int z = edge[x][i].second;
if (z == prev)
continue;
d[y] = d[x] + z;
cc[y] = d[y] % 2;
dfs(y, x);
}
}
int main() {
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
c = c % 2;
edge[a].push_back(make_pair(b, c));
edge[b].push_back(make_pair(a, c));
}
dfs(0, -1);
for (int i = 0; i < n; i++)
cout << cc[i] << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int n;
int d[100005], cc[100005];
vector<pair<int, int>> edge[100005];
void dfs(int x, int prev) {
for (int i = 0; i < edge[x].size(); i++) {
int y = edge[x][i].first;
int z = edge[x][i].second;
if (y == prev)
continue;
d[y] = d[x] + z;
cc[y] = d[y] % 2;
dfs(y, x);
}
}
int main() {
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
c = c % 2;
edge[a].push_back(make_pair(b, c));
edge[b].push_back(make_pair(a, c));
}
dfs(0, -1);
for (int i = 0; i < n; i++)
cout << cc[i] << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
const int MOD = 1000000007;
const int INF = 1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll, int, int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;
bool visited[100005];
vp g[100005];
int colors[100005];
void dfs(int s) {
visited[s] = true;
for (int i = 0; i < int(g[s].size()); i++) {
int to = g[s][i].first;
int len = g[s][i].second;
if (visited[to])
continue;
else {
if (len % 2 == 0) {
colors[to] = colors[s];
dfs(to);
} else {
colors[to] = (colors[s] + 1) % 2;
dfs(to);
}
}
}
}
int main(int argc, char const *argv[]) {
int N;
memset(visited, false, sizeof(visited));
colors[1] = 0;
cin >> N;
for (int i = 0; i < N - 1; i++) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back(pii(v, w));
g[v].push_back(pii(w, v));
}
dfs(1);
for (int i = 1; i <= N; i++) {
cout << colors[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
const int MOD = 1000000007;
const int INF = 1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll, int, int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;
bool visited[100005];
vp g[100005];
int colors[100005];
void dfs(int s) {
visited[s] = true;
for (int i = 0; i < int(g[s].size()); i++) {
int to = g[s][i].first;
int len = g[s][i].second;
if (visited[to])
continue;
else {
if (len % 2 == 0) {
colors[to] = colors[s];
dfs(to);
} else {
colors[to] = (colors[s] + 1) % 2;
dfs(to);
}
}
}
}
int main(int argc, char const *argv[]) {
int N;
memset(visited, false, sizeof(visited));
colors[1] = 0;
cin >> N;
for (int i = 0; i < N - 1; i++) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back(pii(v, w));
g[v].push_back(pii(u, w));
}
dfs(1);
for (int i = 1; i <= N; i++) {
cout << colors[i] << endl;
}
return 0;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p03044 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define FORe(i, k, n) for (int i = (k); i <= (n); i++)
#define FORr(i, k, n) for (int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for (int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
vector<vector<int>> to(100000);
map<P, int> weight;
vector<int> color(10000);
void dfs(int u, int p = -1, int len = 0) {
if (len)
color[u] = 1;
for (int v : to[u]) {
if (v == p)
continue;
int w = weight[P(u, v)];
dfs(v, u, len xor w);
}
}
int main(void) {
int n;
cin >> n;
REP(i, n - 1) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
w %= 2;
to[u].emplace_back(v);
to[v].emplace_back(u);
weight[P(u, v)] = w;
weight[P(v, u)] = w;
}
dfs(0);
REP(i, n) cout << color[i] << endl;
return 0;
} | #include <bits/stdc++.h>
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define FORe(i, k, n) for (int i = (k); i <= (n); i++)
#define FORr(i, k, n) for (int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for (int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
vector<vector<int>> to(100000);
map<P, int> weight;
vector<int> color(100000);
void dfs(int u, int p = -1, int len = 0) {
if (len)
color[u] = 1;
for (int v : to[u]) {
if (v == p)
continue;
int w = weight[P(u, v)];
dfs(v, u, len xor w);
}
}
int main(void) {
int n;
cin >> n;
REP(i, n - 1) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
w %= 2;
to[u].emplace_back(v);
to[v].emplace_back(u);
weight[P(u, v)] = w;
weight[P(v, u)] = w;
}
dfs(0);
REP(i, n) cout << color[i] << endl;
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.