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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03261 | C++ | Runtime Error | // ↓template↓
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll> dij;
struct edge {
ll to, cost;
};
vector<vector<edge>> G;
ll mod_pow(ll a, ll b) {
ll res = 1, mul = a;
for (int i = 0; i < 31; ++i) {
if (b >> i & 1) {
res *= mul;
res %= MOD;
}
mul = (mul * mul) % MOD;
}
return res;
}
void addedge(int from, int to, int cost) {
G[from].push_back({to, cost});
G[to].push_back({from, cost});
}
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);
}
template <typename T> void outp(vector<T> v) {
for (int i = 0; i < v.size(); ++i) {
cout << v[i];
if (i != v.size() - 1) {
cout << " ";
}
}
}
// ↑template↑
int main() {
int n;
cin >> n;
vector<string> v;
bool ok = 1;
for (int i = 0; i < n; ++i) {
cin >> v[i];
if (i != 0) {
if (v[i][0] != v[i - 1][v[i - 1].length() - 1]) {
ok = 0;
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != j && v[i] == v[j]) {
ok = 0;
}
}
}
if (ok) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | // ↓template↓
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n) n.begin(), n.end()
#define rall(n) n.rbegin(), n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll> dij;
struct edge {
ll to, cost;
};
vector<vector<edge>> G;
ll mod_pow(ll a, ll b) {
ll res = 1, mul = a;
for (int i = 0; i < 31; ++i) {
if (b >> i & 1) {
res *= mul;
res %= MOD;
}
mul = (mul * mul) % MOD;
}
return res;
}
void addedge(int from, int to, int cost) {
G[from].push_back({to, cost});
G[to].push_back({from, cost});
}
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);
}
template <typename T> void outp(vector<T> v) {
for (int i = 0; i < v.size(); ++i) {
cout << v[i];
if (i != v.size() - 1) {
cout << " ";
}
}
}
// ↑template↑
int main() {
int n;
cin >> n;
vector<string> v(n);
bool ok = 1;
for (int i = 0; i < n; ++i) {
cin >> v[i];
if (i != 0) {
if (v[i][0] != v[i - 1][v[i - 1].length() - 1]) {
ok = 0;
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != j && v[i] == v[j]) {
ok = 0;
}
}
}
if (ok) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | replace | 70 | 71 | 70 | 71 | -11 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, i, j, k;
string s[12];
int main() {
cin >> n;
for (i = 0; i < n; i++)
cin >> s[i];
for (i = 1; i < n; i++) {
if (s[i][0] != s[i - 1][s[i - 1].size() - 1]) {
cout << "No";
return 0;
}
for (j = 0; j < i; j++) {
if (s[i].size() != s[j].size())
continue;
for (k = 0; k < s[i].size(); k++) {
if (s[i][k] != s[j][k])
break;
}
if (k == s[i].size())
break;
}
if (j < i)
break;
}
if (i < n)
cout << "No";
else
cout << "Yes";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, i, j, k;
string s[102];
int main() {
cin >> n;
for (i = 0; i < n; i++)
cin >> s[i];
for (i = 1; i < n; i++) {
if (s[i][0] != s[i - 1][s[i - 1].size() - 1]) {
cout << "No";
return 0;
}
for (j = 0; j < i; j++) {
if (s[i].size() != s[j].size())
continue;
for (k = 0; k < s[i].size(); k++) {
if (s[i][k] != s[j][k])
break;
}
if (k == s[i].size())
break;
}
if (j < i)
break;
}
if (i < n)
cout << "No";
else
cout << "Yes";
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03261 | C++ | Runtime Error | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
string x, y;
vector<string> buff;
cin >> a;
cin >> x;
buff.push_back(x);
for (int i = 1; i < a; i++) {
cin >> x;
if (x[0] == buff[i - 1].back()) {
for (int j = 0; j < i; j++) {
if (x == buff[j]) {
cout << "No" << endl;
return 0;
}
}
buff.push_back(x);
}
}
cout << "Yes" << endl;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
string x, y;
vector<string> buff;
cin >> a;
cin >> x;
buff.push_back(x);
for (int i = 1; i < a; i++) {
cin >> x;
if (x[0] == buff[i - 1].back()) {
for (int j = 0; j < i; j++) {
if (x == buff[j]) {
cout << "No" << endl;
return 0;
}
}
buff.push_back(x);
} else {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | insert | 24 | 24 | 24 | 27 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<string> w = {s};
for (int i = 0; i < n - 1; i++) {
cin >> s;
if (s.at(0) != w.at(i).at(w.at(i).size() - 1)) {
cout << "No" << endl;
return 0;
}
for (int j = 0; j < w.size(); j++) {
if (s == w.at(j)) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<string> w = {s};
for (int i = 0; i < n - 1; i++) {
cin >> s;
if (s.at(0) != w.at(i).at(w.at(i).size() - 1)) {
cout << "No" << endl;
return 0;
}
for (int j = 0; j < w.size(); j++) {
if (s == w.at(j)) {
cout << "No" << endl;
return 0;
}
}
w.push_back(s);
}
cout << "Yes" << endl;
} | insert | 20 | 20 | 20 | 21 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 1) >= this->size() (which is 1)
|
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string w[100];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> w[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (w[j] == w[i]) {
cout << "No" << endl;
return 0;
}
}
if (w[i][0] != w[i - 1][w[i - 1].size() - 1]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string w[100];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> w[i];
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (w[j] == w[i]) {
cout << "No" << endl;
return 0;
}
}
if (w[i][0] != w[i - 1][w[i - 1].size() - 1]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | replace | 9 | 10 | 9 | 10 | -11 | |
p03261 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
int main() {
using namespace std;
long long a = 0, b = 0, c = 0, d = 0, e = 0, min = 0, ma = 0, ans = 0,
count = 0, nagax = 0, nagay = 0, size = 0;
int once[100020] = {}, info[100020] = {};
std::string str[100], strs;
bool okada = false, okada2 = true;
cin >> a;
for (int i = 1; i <= a; i++) {
cin >> str[i];
}
for (int i = 2; i <= a; i++) {
size = str[i - 1].size();
if (str[i].at(0) != str[i - 1].at(size - 1)) {
cout << "No" << endl;
return 0;
}
}
for (int i = 1; i <= a - 1; i++) {
for (int j = i + 1; j <= a; j++) {
if (str[i] == str[j]) {
okada2 = false;
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
int main() {
using namespace std;
long long a = 0, b = 0, c = 0, d = 0, e = 0, min = 0, ma = 0, ans = 0,
count = 0, nagax = 0, nagay = 0, size = 0;
int once[100020] = {}, info[100020] = {};
std::string str[150], strs;
bool okada = false, okada2 = true;
cin >> a;
for (int i = 1; i <= a; i++) {
cin >> str[i];
}
for (int i = 2; i <= a; i++) {
size = str[i - 1].size();
if (str[i].at(0) != str[i - 1].at(size - 1)) {
cout << "No" << endl;
return 0;
}
}
for (int i = 1; i <= a - 1; i++) {
for (int j = i + 1; j <= a; j++) {
if (str[i] == str[j]) {
okada2 = false;
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n;
cin >> n;
vector<string> a(n);
rep(i, n) { cin >> a[i]; }
rep(i, n - 1) {
if (a[i][a[i].size() - 1] != a[i + 1][0]) {
cout << "No" << endl;
return 0;
}
for (int j = i + 1; j <= n; j++) {
if (a[i] == a[j]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n;
cin >> n;
vector<string> a(n);
rep(i, n) { cin >> a[i]; }
rep(i, n - 1) {
if (a[i][a[i].size() - 1] != a[i + 1][0]) {
cout << "No" << endl;
return 0;
}
for (int j = i + 1; j < n; j++) {
if (a[i] == a[j]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int main() {
int N, out = 0;
cin >> N;
string siritori[150];
for (int i = 0; i < N; i++) {
cin >> siritori[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i != j && siritori[i] == siritori[j]) {
cout << "No" << endl;
return 0;
}
}
}
for (int i = 1; i < N; i++) {
if (siritori[i - 1].at(siritori[i - 1].size()) != siritori[i].at(0)) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int main() {
int N, out = 0;
cin >> N;
string siritori[150];
for (int i = 0; i < N; i++) {
cin >> siritori[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i != j && siritori[i] == siritori[j]) {
cout << "No" << endl;
return 0;
}
}
}
for (int i = 1; i < N; i++) {
if (siritori[i - 1].at(siritori[i - 1].size() - 1) != siritori[i].at(0)) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAX 10
using namespace std;
int main() {
int n;
string s[MAX];
bool t = true;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s[i];
if (i && s[i - 1][s[i - 1].length() - 1] != s[i][0])
t = false;
for (int j = 0; j < i; j++) {
if (s[j] == s[i])
t = false;
}
}
cout << (t ? "Yes" : "No") << endl;
} | #include <bits/stdc++.h>
#define MAX 105
using namespace std;
int main() {
int n;
string s[MAX];
bool t = true;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s[i];
if (i && s[i - 1][s[i - 1].length() - 1] != s[i][0])
t = false;
for (int j = 0; j < i; j++) {
if (s[j] == s[i])
t = false;
}
}
cout << (t ? "Yes" : "No") << endl;
}
| replace | 1 | 2 | 1 | 2 | 0 | |
p03261 | C++ | Runtime Error | #include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
// Your code here!
vector<string> shiritori;
string buf;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> buf;
shiritori.push_back(buf);
}
for (int i = 0; i < N; i++) {
for (int j = N; j > i; j--) {
if (shiritori[j] == shiritori[i]) {
cout << "No";
return 0;
}
}
if (i < N - 1) {
if (shiritori[i][shiritori[i].size() - 1] != shiritori[i + 1][0]) {
cout << "No";
return 0;
}
}
}
cout << "Yes";
return 0;
}
| #include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
// Your code here!
vector<string> shiritori;
string buf;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> buf;
shiritori.push_back(buf);
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < i; j++) {
if (shiritori[j] == shiritori[i]) {
cout << "No";
return 0;
}
}
if (i < N - 1) {
if (shiritori[i][shiritori[i].size() - 1] != shiritori[i + 1][0]) {
cout << "No";
return 0;
}
}
}
cout << "Yes";
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p03261 | C++ | Runtime Error | #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
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FORR(i, n, m) for (int i = n - 1; i >= m; i--)
#define all(in) in.begin(), in.end()
#define ALL(in, K) in, in + K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 3.14159265358979323846
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
static string str[1000];
REP(i, n) cin >> str[i];
REP(i, n) {
if (str[i - 1][str[i - 1].size() - 1] != str[i][0] && i > 0) {
// cout << str[i-1][str[i-1].size()-1] << ":" << str[i][0] << endl;
cout << "No" << endl;
return 0;
}
REP(j, i) {
// cout << str[j] << ":" << str[i] << endl;
if (str[i] == str[j]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
} | #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
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FORR(i, n, m) for (int i = n - 1; i >= m; i--)
#define all(in) in.begin(), in.end()
#define ALL(in, K) in, in + K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 3.14159265358979323846
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
static string str[1000];
REP(i, n) cin >> str[i];
REP(i, n) {
// cout << str[i-1][str[i-1].size()-1] << ":" << str[i][0] << endl;
if (i > 0)
if (str[i - 1][str[i - 1].size() - 1] != str[i][0]) {
cout << "No" << endl;
return 0;
}
REP(j, i) {
// cout << str[j] << ":" << str[i] << endl;
if (str[i] == str[j]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
} | replace | 116 | 121 | 116 | 122 | -11 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> W(n);
copy_n(istream_iterator<string>(cin), n, W.begin());
for (int i = 0; i < n - 1; i++) {
if (W[i][W[i].size() - 1] != W[i + 1][0]) {
return puts("No");
}
}
sort(W.begin(), W.end());
puts(unique(W.begin(), W.end()) == W.end() ? "Yes" : "No");
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> W(n);
copy_n(istream_iterator<string>(cin), n, W.begin());
for (int i = 0; i < n - 1; i++) {
if (W[i][W[i].size() - 1] != W[i + 1][0]) {
puts("No");
return 0;
}
}
sort(W.begin(), W.end());
puts(unique(W.begin(), W.end()) == W.end() ? "Yes" : "No");
} | replace | 11 | 12 | 11 | 13 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
int a, b;
map<string, int> mp;
string s[100];
int main() {
int n;
cin >> n;
rep(i, 1, n) {
cin >> s[i];
if (mp.count(s[i])) {
cout << "No";
return 0;
}
int sz = s[i - 1].size();
if (i > 1 && s[i][0] != s[i - 1][sz - 1]) {
cout << "No";
return 0;
}
mp[s[i]] = 1;
}
cout << "Yes";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
int a, b;
map<string, int> mp;
string s[105];
int main() {
int n;
cin >> n;
rep(i, 1, n) {
cin >> s[i];
if (mp.count(s[i])) {
cout << "No";
return 0;
}
int sz = s[i - 1].size();
if (i > 1 && s[i][0] != s[i - 1][sz - 1]) {
cout << "No";
return 0;
}
mp[s[i]] = 1;
}
cout << "Yes";
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03261 | C++ | Runtime Error | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, ans = 0, same = 0;
string s;
vector<string> w;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
w.push_back(s);
}
for (int i = 0; i < n; i++) {
if (w[i].back() == w[i + 1].front() && i != (n - 1))
ans++;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j != i && w[i] == w[j])
same++;
}
}
if (same == 0 && ans == (n - 1))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, ans = 0, same = 0;
string s;
vector<string> w;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
w.push_back(s);
}
for (int i = 0; i < (n - 1); i++) {
if (w[i].back() == w[i + 1].front())
ans++;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j != i && w[i] == w[j])
same++;
}
}
if (same == 0 && ans == (n - 1))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | replace | 13 | 15 | 13 | 15 | -11 | |
p03261 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n, a = 1;
string w[10] = {};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> w[i];
}
for (int i = 0; i < n - 1; i++) {
if (w[i][w[i].size() - 1] != w[i + 1][0])
a = 0;
}
// cout<<a<<endl;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (w[i] == w[j])
a = 0;
}
}
if (a == 1)
cout << "Yes" << endl;
else if (a == 0)
cout << "No" << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int n, a = 1;
string w[100] = {};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> w[i];
}
for (int i = 0; i < n - 1; i++) {
if (w[i][w[i].size() - 1] != w[i + 1][0])
a = 0;
}
// cout<<a<<endl;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (w[i] == w[j])
a = 0;
}
}
if (a == 1)
cout << "Yes" << endl;
else if (a == 0)
cout << "No" << endl;
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03261 | C++ | Runtime Error | #include <iostream>
#include <string.h>
char c[10], d[10];
std::string b[100];
int a, e, f = 0;
int main() {
std::cin >> a;
for (int i = 1; i <= a; i++) {
std::cin >> c;
if (i > 1) {
if (c[0] != d[e - 1]) {
f = 1;
}
}
strcpy(d, c);
e = strlen(d);
b[i] = std::string(d);
for (int j = 1; j < i; j++) {
if (b[i] == b[j]) {
f = 1;
}
}
}
if (f == 1) {
std::cout << "No";
} else {
std::cout << "Yes";
}
} | #include <iostream>
#include <string.h>
char c[20], d[20];
std::string b[110];
int a, e, f = 0;
int main() {
std::cin >> a;
for (int i = 1; i <= a; i++) {
std::cin >> c;
if (i > 1) {
if (c[0] != d[e - 1]) {
f = 1;
}
}
strcpy(d, c);
e = strlen(d);
b[i] = std::string(d);
for (int j = 1; j < i; j++) {
if (b[i] == b[j]) {
f = 1;
}
}
}
if (f == 1) {
std::cout << "No";
} else {
std::cout << "Yes";
}
} | replace | 2 | 4 | 2 | 4 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
int main() {
int n;
cin >> n;
vector<string> w(n);
rep(i, n) { cin >> w.at(i); }
bool flag = true;
rep(i, n) {
rep(j, n) {
if (i == j)
continue;
else {
if (w.at(i) == w.at(j)) {
flag = false;
}
}
}
}
if (flag == false) {
cout << "No" << endl;
exit(1);
}
rep(i, n - 1) {
if (w.at(i).at(w.at(i).size() - 1) != w.at(i + 1).at(0)) {
flag = false;
break;
} else {
continue;
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
int main() {
int n;
cin >> n;
vector<string> w(n);
rep(i, n) { cin >> w.at(i); }
bool flag = true;
rep(i, n) {
rep(j, n) {
if (i == j)
continue;
else {
if (w.at(i) == w.at(j)) {
flag = false;
}
}
}
}
if (flag == true) {
rep(i, n - 1) {
if (w.at(i).at(w.at(i).size() - 1) != w.at(i + 1).at(0)) {
flag = false;
break;
} else {
continue;
}
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | replace | 23 | 34 | 23 | 31 | 1 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
// hamko utils
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) \
for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template <class T1, class T2> bool chmin(T1 &a, T2 b) {
return b < a && (a = b, true);
}
template <class T1, class T2> bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using ld = long double;
using vld = vector<ld>;
using vi = vector<int>;
using vvi = vector<vi>;
vll conv(vi &v) {
vll r(v.size());
rep(i, v.size()) r[i] = v[i];
return r;
}
inline void input(int &v) {
v = 0;
char c = 0;
int p = 1;
while (c < '0' || c > '9') {
if (c == '-')
p = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
v = (v << 3) + (v << 1) + c - '0';
c = getchar();
}
v *= p;
} // これを使うならば、tieとかを消して!!
template <typename T, typename U>
ostream &operator<<(ostream &o, const pair<T, U> &v) {
o << "(" << v.first << ", " << v.second << ")";
return o;
}
template <size_t...> struct seq {};
template <size_t N, size_t... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
template <size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {};
template <class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) {
using s = int[];
(void)s{0, (void(os << (Is == 0 ? "" : ", ") << get<Is>(t)), 0)...};
}
template <class Ch, class Tr, class... Args>
auto operator<<(basic_ostream<Ch, Tr> &os, tuple<Args...> const &t)
-> basic_ostream<Ch, Tr> & {
os << "(";
print_tuple(os, t, gen_seq<sizeof...(Args)>());
return os << ")";
}
ostream &operator<<(ostream &o, const vvll &v) {
rep(i, v.size()) {
rep(j, v[i].size()) o << v[i][j] << " ";
o << endl;
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << '[';
rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : "");
o << "]";
return o;
}
template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) {
o << '[';
rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : "");
o << "]";
return o;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T>
ostream &operator<<(ostream &o, const unordered_set<T> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T, typename U>
ostream &operator<<(ostream &o, const map<T, U> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it;
o << "]";
return o;
}
vector<int> range(const int x, const int y) {
vector<int> v(y - x + 1);
iota(v.begin(), v.end(), x);
return v;
}
template <typename T> istream &operator>>(istream &i, vector<T> &o) {
rep(j, o.size()) i >> o[j];
return i;
}
template <typename T, typename S, typename U>
ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.top();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.front();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.top();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> unordered_map<T, ll> counter(vector<T> vec) {
unordered_map<T, ll> ret;
for (auto &&x : vec)
ret[x]++;
return ret;
};
string substr(string s, P x) { return s.substr(x.fi, x.se - x.fi); }
void vizGraph(vvll &g, int mode = 0, string filename = "out.png") {
ofstream ofs("./out.dot");
ofs << "digraph graph_name {" << endl;
set<P> memo;
rep(i, g.size()) rep(j, g[i].size()) {
if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i))))
continue;
memo.insert(P(i, g[i][j]));
ofs << " " << i << " -> " << g[i][j]
<< (mode ? " [arrowhead = none]" : "") << endl;
}
ofs << "}" << endl;
ofs.close();
system(((string) "dot -T png out.dot >" + filename).c_str());
}
size_t random_seed;
namespace std {
using argument_type = P;
template <> struct hash<argument_type> {
size_t operator()(argument_type const &x) const {
size_t seed = random_seed;
seed ^= hash<ll>{}(x.fi);
seed ^= (hash<ll>{}(x.se) << 1);
return seed;
}
};
}; // namespace std
#define ldout fixed << setprecision(40)
#define EPS (double)1e-14
#define INF (ll)1e18
#define mo (ll)(1e9 + 7)
// end of hamko utils
int main() {
int N;
cin >> N;
string W[N];
bool ok = true;
for (int i = 0; i < N; ++i) {
cin >> W[i];
char a = W[i - 1].back();
char b = W[i].front();
if (i > 0 && a != b)
ok = false;
}
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (W[i] == W[j]) {
ok = false;
}
}
}
if (ok)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
// hamko utils
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) \
for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template <class T1, class T2> bool chmin(T1 &a, T2 b) {
return b < a && (a = b, true);
}
template <class T1, class T2> bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using ld = long double;
using vld = vector<ld>;
using vi = vector<int>;
using vvi = vector<vi>;
vll conv(vi &v) {
vll r(v.size());
rep(i, v.size()) r[i] = v[i];
return r;
}
inline void input(int &v) {
v = 0;
char c = 0;
int p = 1;
while (c < '0' || c > '9') {
if (c == '-')
p = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
v = (v << 3) + (v << 1) + c - '0';
c = getchar();
}
v *= p;
} // これを使うならば、tieとかを消して!!
template <typename T, typename U>
ostream &operator<<(ostream &o, const pair<T, U> &v) {
o << "(" << v.first << ", " << v.second << ")";
return o;
}
template <size_t...> struct seq {};
template <size_t N, size_t... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
template <size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {};
template <class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) {
using s = int[];
(void)s{0, (void(os << (Is == 0 ? "" : ", ") << get<Is>(t)), 0)...};
}
template <class Ch, class Tr, class... Args>
auto operator<<(basic_ostream<Ch, Tr> &os, tuple<Args...> const &t)
-> basic_ostream<Ch, Tr> & {
os << "(";
print_tuple(os, t, gen_seq<sizeof...(Args)>());
return os << ")";
}
ostream &operator<<(ostream &o, const vvll &v) {
rep(i, v.size()) {
rep(j, v[i].size()) o << v[i][j] << " ";
o << endl;
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << '[';
rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : "");
o << "]";
return o;
}
template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) {
o << '[';
rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : "");
o << "]";
return o;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T>
ostream &operator<<(ostream &o, const unordered_set<T> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T, typename U>
ostream &operator<<(ostream &o, const map<T, U> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it;
o << "]";
return o;
}
vector<int> range(const int x, const int y) {
vector<int> v(y - x + 1);
iota(v.begin(), v.end(), x);
return v;
}
template <typename T> istream &operator>>(istream &i, vector<T> &o) {
rep(j, o.size()) i >> o[j];
return i;
}
template <typename T, typename S, typename U>
ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.top();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.front();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.top();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> unordered_map<T, ll> counter(vector<T> vec) {
unordered_map<T, ll> ret;
for (auto &&x : vec)
ret[x]++;
return ret;
};
string substr(string s, P x) { return s.substr(x.fi, x.se - x.fi); }
void vizGraph(vvll &g, int mode = 0, string filename = "out.png") {
ofstream ofs("./out.dot");
ofs << "digraph graph_name {" << endl;
set<P> memo;
rep(i, g.size()) rep(j, g[i].size()) {
if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i))))
continue;
memo.insert(P(i, g[i][j]));
ofs << " " << i << " -> " << g[i][j]
<< (mode ? " [arrowhead = none]" : "") << endl;
}
ofs << "}" << endl;
ofs.close();
system(((string) "dot -T png out.dot >" + filename).c_str());
}
size_t random_seed;
namespace std {
using argument_type = P;
template <> struct hash<argument_type> {
size_t operator()(argument_type const &x) const {
size_t seed = random_seed;
seed ^= hash<ll>{}(x.fi);
seed ^= (hash<ll>{}(x.se) << 1);
return seed;
}
};
}; // namespace std
#define ldout fixed << setprecision(40)
#define EPS (double)1e-14
#define INF (ll)1e18
#define mo (ll)(1e9 + 7)
// end of hamko utils
int main() {
int N;
cin >> N;
string W[N];
bool ok = true;
for (int i = 0; i < N; ++i) {
cin >> W[i];
if (i > 0 && W[i - 1].back() != W[i].front())
ok = false;
}
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (W[i] == W[j]) {
ok = false;
}
}
}
if (ok)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | replace | 206 | 209 | 206 | 207 | -11 | |
p03261 | C++ | Runtime Error | #include <iostream>
#include <list>
#include <string>
using namespace std;
int main() {
int n, flg;
cin >> n;
flg = 0;
string w[10];
for (int i = 0; i < n; i++) {
cin >> w[i];
} /*
for(int i=0;i<n;i++){
cout<<w[i]<<"\n";
}
*/
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (w[j] == w[i]) {
flg = 1;
}
}
}
// cout<<"checked same words flg=="<<flg<<"\n";
for (int i = 0; i < n - 1; i++) {
if (w[i].back() != w[i + 1][0]) {
// cout<<"w["<<i<<"].back()="<<w[i].back()<<"
// w["<<i+1<<"][0]="<<w[i+1][0]<<"\n";
flg = 1;
}
}
// cout<<"checked chain words flg=="<<flg<<"\n";
if (flg == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
} | #include <iostream>
#include <list>
#include <string>
using namespace std;
int main() {
int n, flg;
cin >> n;
flg = 0;
string w[100];
for (int i = 0; i < n; i++) {
cin >> w[i];
} /*
for(int i=0;i<n;i++){
cout<<w[i]<<"\n";
}
*/
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (w[j] == w[i]) {
flg = 1;
}
}
}
// cout<<"checked same words flg=="<<flg<<"\n";
for (int i = 0; i < n - 1; i++) {
if (w[i].back() != w[i + 1][0]) {
// cout<<"w["<<i<<"].back()="<<w[i].back()<<"
// w["<<i+1<<"][0]="<<w[i+1][0]<<"\n";
flg = 1;
}
}
// cout<<"checked chain words flg=="<<flg<<"\n";
if (flg == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> W(N);
for (int i = 0; i < N; i++)
cin >> W.at(i);
set<string> S;
S.insert(W.at(0));
bool ans = true;
for (int i = 1; i < N; i++) {
if (S.count(W.at(i))) {
ans = false;
break;
} else {
if (W.at(i).at(0) != W.at(i - 1).at(W.at(i - 1).size()) - 1) {
ans = false;
break;
} else
S.insert(W.at(i));
}
}
if (ans)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> W(N);
for (int i = 0; i < N; i++)
cin >> W.at(i);
set<string> S;
S.insert(W.at(0));
bool ans = true;
for (int i = 1; i < N; i++) {
if (S.count(W.at(i))) {
ans = false;
break;
} else {
if (W.at(i).at(0) != W.at(i - 1).at(W.at(i - 1).size() - 1)) {
ans = false;
break;
} else
S.insert(W.at(i));
}
}
if (ans)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | replace | 16 | 17 | 16 | 17 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p03261 | C++ | Runtime Error | #include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <utility>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
char str[1005] = {};
int n;
char *begin[105] = {};
begin[0] = &str[0];
int poi = 0;
scanf("%d\n", &n);
for (int i = 0; i < n; i++) {
scanf("%s\n", begin[i]);
while (str[poi] != '\0')
poi++;
begin[i + 1] = &str[poi + 1];
poi++;
if (i > 0) {
if (*begin[i] != *(begin[i] - 2)) {
printf("No\n");
return 0;
}
}
REP(k, i - 1) {
if (strcmp(begin[i], begin[k]) == 0) {
printf("No\n");
return 0;
}
}
}
printf("Yes\n");
return 0;
} | #include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <utility>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
char str[1500] = {};
int n;
char *begin[105] = {};
begin[0] = &str[0];
int poi = 0;
scanf("%d\n", &n);
for (int i = 0; i < n; i++) {
scanf("%s\n", begin[i]);
while (str[poi] != '\0')
poi++;
begin[i + 1] = &str[poi + 1];
poi++;
if (i > 0) {
if (*begin[i] != *(begin[i] - 2)) {
printf("No\n");
return 0;
}
}
REP(k, i - 1) {
if (strcmp(begin[i], begin[k]) == 0) {
printf("No\n");
return 0;
}
}
}
printf("Yes\n");
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03261 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int a, flag = 0;
cin >> a;
vector<string> b(a);
for (int i = 0; i < a; i++)
cin >> b.at(i);
for (int i = 0; i < a - 1; i++) {
for (int j = i + 1; j < a; j++) {
if (b.at(i) == b.at(j))
flag = 1;
}
}
for (int i = 0; i < a - 1; i++) {
string c, d;
c = b.at(i);
d = b.at(i + 1);
if (c.at(c.size()) != d.at(0))
flag = 1;
}
if (flag)
cout << "No";
else
cout << "Yes";
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int a, flag = 0;
cin >> a;
vector<string> b(a);
for (int i = 0; i < a; i++)
cin >> b.at(i);
for (int i = 0; i < a - 1; i++) {
for (int j = i + 1; j < a; j++) {
if (b.at(i) == b.at(j))
flag = 1;
}
}
for (int i = 0; i < a - 1; i++) {
string c, d;
c = b.at(i);
d = b.at(i + 1);
if (c.at(c.size() - 1) != d.at(0))
flag = 1;
}
if (flag)
cout << "No";
else
cout << "Yes";
} | replace | 19 | 20 | 19 | 20 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
bool s = true;
string a[100];
set<string> b;
for (i = 0; i < n; i++) {
cin >> a[i];
b.insert(a[i]);
}
for (i = 0; i < n - 1; i++) {
if (a[i].at(a[i].size() - 1) != a[i + 1].at(0)) {
s = false;
}
}
cout << (b.size() / n && s ? "Yes" : "No");
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
bool s = true;
string a[100];
set<string> b;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
b.insert(a[i]);
}
for (i = 0; i < n - 1; i++) {
if (a[i].at(a[i].size() - 1) != a[i + 1].at(0)) {
s = false;
}
}
cout << (b.size() / n && s ? "Yes" : "No");
} | insert | 7 | 7 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03261 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a = 0, size = 0;
std::string str[100] = {};
bool okada = true;
cin >> a;
cin >> str[0];
for (int i = 1; i < a; i++) {
cin >> str[i];
if (a == 2) {
cout << "No" << endl;
return 0;
}
if (i > 1 && str[i][0] != str[i - 1][size - 1]) {
cout << "No" << endl;
return 0;
}
size = str[i].size();
}
for (int i = 0; i < a; i++) {
for (int j = i + 1; j < a + 1; j++) {
if (str[i] == str[j]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a = 0, size = 0;
std::string str[100] = {};
bool okada = true;
cin >> a;
cin >> str[0];
for (int i = 1; i < a; i++) {
cin >> str[i];
if (a == 2) {
cout << "No" << endl;
return 0;
}
if (i > 1 && str[i][0] != str[i - 1][size - 1]) {
cout << "No" << endl;
return 0;
}
size = str[i].size();
}
for (int i = 0; i < a - 1; i++) {
for (int j = i + 1; j < a; j++) {
if (str[i] == str[j]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
} | replace | 46 | 48 | 46 | 48 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int main() {
cout << fixed << setprecision(10);
int N;
cin >> N;
vector<string> W(N);
bool ans = true;
rep(i, N) { cin >> W[i]; }
rep(i, N) {
int M = W[i].size();
if (W[i].back() != W[i + 1].front()) {
ans = false;
}
for (int j = i + 1; j < N; j++) {
if (W[i] == W[j]) {
ans = false;
}
}
}
if (ans == true) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int main() {
cout << fixed << setprecision(10);
int N;
cin >> N;
vector<string> W(N);
bool ans = true;
rep(i, N) { cin >> W[i]; }
rep(i, N - 1) {
int M = W[i].size();
if (W[i].back() != W[i + 1].front()) {
ans = false;
}
for (int j = i + 1; j < N; j++) {
if (W[i] == W[j]) {
ans = false;
}
}
}
if (ans == true) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| replace | 20 | 21 | 20 | 21 | -11 | |
p03261 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;
int main() {
int n;
cin >> n;
vector<string> w;
rep(i, n) cin >> w[i];
unordered_set<string> a;
a.insert(w[0]);
rep(i, n - 1) {
if (a.count(w[i + 1]) > 0 ||
w[i].substr(w[i].size() - 1, 1) != w[i + 1].substr(0, 1)) {
cout << "No" << endl;
return 0;
}
a.insert(w[i + 1]);
}
cout << "Yes" << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;
int main() {
int n;
cin >> n;
vector<string> w(n);
rep(i, n) cin >> w[i];
unordered_set<string> a;
a.insert(w[0]);
rep(i, n - 1) {
if (a.count(w[i + 1]) > 0 ||
w[i].substr(w[i].size() - 1, 1) != w[i + 1].substr(0, 1)) {
cout << "No" << endl;
return 0;
}
a.insert(w[i + 1]);
}
cout << "Yes" << endl;
return 0;
} | replace | 20 | 21 | 20 | 21 | -11 | |
p03261 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<string> w(n);
rep(i, n) cin >> w[i];
rep(i, n - 1) {
if (w[i][w[i].size() - 1] != w[i + 1][0]) {
cout << "No" << endl;
return 0;
}
}
sort(w.begin(), w.end());
rep(i, n) {
if (w[i] == w[i + 1]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<string> w(n);
rep(i, n) cin >> w[i];
rep(i, n - 1) {
if (w[i][w[i].size() - 1] != w[i + 1][0]) {
cout << "No" << endl;
return 0;
}
}
sort(w.begin(), w.end());
rep(i, n - 1) {
if (w[i] == w[i + 1]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03261 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll long long int
// #define INT_MAX 5000000
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define revp(i, n) for (i = (n - 1); i >= 0; i--)
#define myrep1(i, a, b) for (i = a; i <= b; i++)
#define myrep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define si short int
#define INTMAX 1000000000
#define MAXN 1000000000000000000
#define MINN -1000000000000000000
// #define INTMAX 1000001000
#define pii pair<ll, ll>
#define pdd pair<double, double>
#define pic pair<int, char>
#define N 700010
#define lgn 20
#define ddouble long double
#define minus minu
#define lgn 20
// #define INTMAX 200000000
// using namespace boost;
// #define si short int
using namespace std;
using namespace __gnu_pbds;
typedef priority_queue<ll, vector<ll>> max_pq;
// typedef priority_queue<pii, vector<pii> , greater<pii > > min_pq;
ll toint(const string &s) {
stringstream ss;
ss << s;
ll x;
ss >> x;
return x;
}
string tostring(ll number) {
stringstream ss;
ss << number;
return ss.str();
}
// using namespace __gnu_pbds;
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
OST;
// typedef priority_queue<pair < ll , pair < pii , ll > > , vector<pair < ll ,
// pair < pii , ll > > > ,greater<pair < ll , pair < pii , ll > > > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << std::endl;
// use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
set<string> s;
ll n;
cin >> n;
char las;
for (ll i = 1; i <= n; i++) {
string c;
cin >> c;
if (s.size() == 0) {
s.insert(c);
las = c[c.size() - 1];
continue;
}
if (s.find(c) != s.end()) {
cout << "No";
return 0;
}
if (c[0] != las) {
cout << "No";
return 0;
}
s.insert(c);
las = c[c.size() - 1];
}
cout << "Yes";
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll long long int
// #define INT_MAX 5000000
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define revp(i, n) for (i = (n - 1); i >= 0; i--)
#define myrep1(i, a, b) for (i = a; i <= b; i++)
#define myrep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define si short int
#define INTMAX 1000000000
#define MAXN 1000000000000000000
#define MINN -1000000000000000000
// #define INTMAX 1000001000
#define pii pair<ll, ll>
#define pdd pair<double, double>
#define pic pair<int, char>
#define N 700010
#define lgn 20
#define ddouble long double
#define minus minu
#define lgn 20
// #define INTMAX 200000000
// using namespace boost;
// #define si short int
using namespace std;
using namespace __gnu_pbds;
typedef priority_queue<ll, vector<ll>> max_pq;
// typedef priority_queue<pii, vector<pii> , greater<pii > > min_pq;
ll toint(const string &s) {
stringstream ss;
ss << s;
ll x;
ss >> x;
return x;
}
string tostring(ll number) {
stringstream ss;
ss << number;
return ss.str();
}
// using namespace __gnu_pbds;
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
OST;
// typedef priority_queue<pair < ll , pair < pii , ll > > , vector<pair < ll ,
// pair < pii , ll > > > ,greater<pair < ll , pair < pii , ll > > > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << std::endl;
// use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
set<string> s;
ll n;
cin >> n;
char las;
for (ll i = 1; i <= n; i++) {
string c;
cin >> c;
if (s.size() == 0) {
s.insert(c);
las = c[c.size() - 1];
continue;
}
if (s.find(c) != s.end()) {
cout << "No";
return 0;
}
if (c[0] != las) {
cout << "No";
return 0;
}
s.insert(c);
las = c[c.size() - 1];
}
cout << "Yes";
}
| replace | 96 | 100 | 96 | 100 | 0 | |
p03261 | Python | Runtime Error | n = int(input())
soFar = []
last = None
flag = True
for i in range(n + 1):
x = input()
if i == 0:
soFar.append(x)
last = x
else:
if x not in soFar and last[len(last) - 1] == x[0]:
soFar.append(x)
last = x
else:
flag = False
break
if flag:
print("Yes")
else:
print("No")
| n = int(input())
w = [input() for i in range(n)]
count = 0
for i in range(1, n):
if w[i - 1][len(w[i - 1]) - 1] != w[i][0]:
count += 1
if count == 0 and len(list(set(w))) == n:
print("Yes")
else:
print("No")
| replace | 1 | 17 | 1 | 7 | 0 | |
p03261 | Python | Runtime Error | #! /usr/bin/python
from sys import stdin
n = int(input())
w = list(map(int, stdin.read().splitlines()))
print("Yes" if n == len(set(w)) else "No")
| #! /usr/bin/python
from sys import stdin
n = int(input())
W = stdin.read().splitlines()
if n != len(set(W)):
print("No")
exit()
for i in range(n - 1):
if W[i][-1] != W[i + 1][0]:
print("No")
exit()
print("Yes")
| replace | 4 | 6 | 4 | 13 | ValueError: invalid literal for int() with base 10: 'hoge' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03261/Python/s621925685.py", line 4, in <module>
w = list(map(int, stdin.read().splitlines()))
ValueError: invalid literal for int() with base 10: 'hoge'
|
p03261 | C++ | Runtime Error | #include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
string s;
set<string> check;
char c = '0';
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (check.count(s)) {
cout << "No" << endl;
return 0;
}
if (c != '0' && c != s.at(i)) {
cout << "No" << endl;
return 0;
}
check.insert(s);
c = s.at(s.size() - 1);
}
cout << "Yes" << endl;
}
| #include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
string s;
set<string> check;
char c = '0';
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
if (check.count(s)) {
cout << "No" << endl;
return 0;
}
if (c != '0' && c != s.at(0)) {
cout << "No" << endl;
return 0;
}
check.insert(s);
c = s.at(s.size() - 1);
}
cout << "Yes" << endl;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p03261 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
const long long h = 0x7ffffff / 2, MAXN = 100 + 5;
long long t[h];
struct Hash {
char st[15];
int hash;
} s[MAXN];
int main() {
int n, sum = 0, hash;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", s[i].st);
hash = 0;
int len = strlen(s[i].st);
for (int j = 0; j < len; j++)
hash = (hash * len + s[i].st[j] - 'a' + 1);
s[i].hash = hash;
if (t[s[i].hash] > 0)
sum = 1;
++t[s[i].hash];
if (i > 1 && s[i - 1].st[strlen(s[i - 1].st) - 1] != s[i].st[0])
sum = 1;
}
sum == 0 ? printf("Yes") : printf("No");
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
const long long h = 0x7ffffff / 2, MAXN = 100 + 5;
long long t[h];
struct Hash {
char st[15];
int hash;
} s[MAXN];
int main() {
int n, sum = 0, hash;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", s[i].st);
hash = 0;
int len = strlen(s[i].st);
for (int j = 0; j < len; j++)
hash = (hash * len + s[i].st[j] - 'a' + 1) % h;
s[i].hash = hash;
if (t[s[i].hash] > 0)
sum = 1;
++t[s[i].hash];
if (i > 1 && s[i - 1].st[strlen(s[i - 1].st) - 1] != s[i].st[0])
sum = 1;
}
sum == 0 ? printf("Yes") : printf("No");
return 0;
} | replace | 22 | 23 | 22 | 23 | -11 | |
p03261 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
int N, flag = 0;
string W[100];
cin >> N;
for (int i = 0; i < N; i++)
cin >> W[i];
for (int i = 0; i < N - 1; i++) {
if (W[i].substr(W[i].length() - 1, 1) != W[i + 1].substr(0, 1)) {
flag++;
break;
}
}
if (flag == 0) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (W[i] == W[i + j + 1]) {
flag++;
break;
}
if (i + j + 1 == N) {
break;
}
}
if (flag != 0)
break;
}
}
if (flag != 0) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
int N, flag = 0;
string W[101];
cin >> N;
for (int i = 0; i < N; i++)
cin >> W[i];
for (int i = 0; i < N - 1; i++) {
if (W[i].substr(W[i].length() - 1, 1) != W[i + 1].substr(0, 1)) {
flag++;
break;
}
}
if (flag == 0) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (W[i] == W[i + j + 1]) {
flag++;
break;
}
if (i + j + 1 == N) {
break;
}
}
if (flag != 0)
break;
}
}
if (flag != 0) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
bool ans = true;
cin >> N;
vector<string> W(N);
for (int i = 0; i < N; i++) {
cin >> W.at(i);
}
for (int i = 1; i < N; i++) {
for (int j = 0; j < i; j++) {
if (W.at(i) == W.at(j)) {
ans = false;
}
}
if (ans == true) {
if (W.at(i - 1).at(W.size() - 1) != W.at(i).at(0)) {
ans = false;
}
}
}
cout << (ans == true ? "Yes" : "No") << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
bool ans = true;
cin >> N;
vector<string> W(N);
for (int i = 0; i < N; i++) {
cin >> W.at(i);
}
for (int i = 1; i < N; i++) {
for (int j = 0; j < i; j++) {
if (W.at(i) == W.at(j)) {
ans = false;
}
}
if (ans == true) {
if (W.at(i - 1).back() != W.at(i).front()) {
ans = false;
}
}
}
cout << (ans == true ? "Yes" : "No") << endl;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, flag = 0;
string str[15];
cin >> n;
cin >> str[0];
for (int i = 1; i < n; i++) {
cin >> str[i];
for (int j = 0; j < i; j++) {
if (str[i] == str[j]) {
flag = 1;
}
}
if (str[i][0] != str[i - 1][str[i - 1].length() - 1]) {
flag = 1;
}
}
if (flag) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, flag = 0;
string str[101];
cin >> n;
cin >> str[0];
for (int i = 1; i < n; i++) {
cin >> str[i];
for (int j = 0; j < i; j++) {
if (str[i] == str[j]) {
flag = 1;
}
}
if (str[i][0] != str[i - 1][str[i - 1].length() - 1]) {
flag = 1;
}
}
if (flag) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0;
cin >> n;
vector<string> w(n);
for (int i = 0; i < n; i++)
cin >> w[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (w[i] == w[j])
count++;
if (count == 2) {
cout << "No";
return 0;
}
}
count = 0;
}
for (int i = 0; i < n; i++) {
if (w[i].back() != w[i + 1].front()) {
cout << "No";
return 0;
}
}
cout << "Yes";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0;
cin >> n;
vector<string> w(n);
for (int i = 0; i < n; i++)
cin >> w[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (w[i] == w[j])
count++;
if (count == 2) {
cout << "No";
return 0;
}
}
count = 0;
}
for (int i = 0; i < n - 1; i++) {
if (w[i].back() != w[i + 1].front()) {
cout << "No";
return 0;
}
}
cout << "Yes";
} | replace | 20 | 21 | 20 | 21 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int sum = 0, sub = 0;
vector<string> vec;
for (int i = 0; i < N; i++) {
cin >> vec[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (vec[i] == vec[j]) {
sub++;
}
}
}
if (sub == N) {
sum++;
} // 条件1
sub = 0;
for (int i = 0; i < N - 1; i++) {
string t = vec[i];
string u = vec[i + 1];
int k = t.size();
if (t.at(k - 1) == u.at(0)) {
sub++;
}
}
if (sub == N - 1) {
sum++;
}
if (sum == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int sum = 0, sub = 0;
vector<string> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (vec[i] == vec[j]) {
sub++;
}
}
}
if (sub == N) {
sum++;
} // 条件1
sub = 0;
for (int i = 0; i < N - 1; i++) {
string t = vec[i];
string u = vec[i + 1];
int k = t.size();
if (t.at(k - 1) == u.at(0)) {
sub++;
}
}
if (sub == N - 1) {
sum++;
}
if (sum == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | replace | 6 | 7 | 6 | 7 | -11 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
bool ad = false;
vector<string> w(n);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (w[i] == w[j]) {
ad = true;
break;
}
}
if (ad)
break;
}
for (int i = 0; i < n; i++) {
if (w[i].back() != w[i + 1].front()) {
ad = true;
break;
}
}
if (ad)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
bool ad = false;
vector<string> w(n);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (w[i] == w[j]) {
ad = true;
break;
}
}
if (ad)
break;
}
for (int i = 0; i < n - 1; i++) {
if (w[i].back() != w[i + 1].front()) {
ad = true;
break;
}
}
if (ad)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
| replace | 21 | 22 | 21 | 22 | -11 | |
p03261 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
string a[11], b, c;
int n, i, x = 0, j;
cin >> n;
cin >> b;
a[0] = b;
for (i = 1; i < n; i++) {
cin >> c;
if (c[0] != b[b.size() - 1]) {
x++;
}
a[i] = c;
b = a[i];
for (j = 0; j < i; j++) {
if (a[i] == a[j]) {
x++;
}
}
}
if (x == 0) {
cout << "Yes";
} else {
cout << "No";
}
} | #include <iostream>
using namespace std;
int main() {
string a[110], b, c;
int n, i, x = 0, j;
cin >> n;
cin >> b;
a[0] = b;
for (i = 1; i < n; i++) {
cin >> c;
if (c[0] != b[b.size() - 1]) {
x++;
}
a[i] = c;
b = a[i];
for (j = 0; j < i; j++) {
if (a[i] == a[j]) {
x++;
}
}
}
if (x == 0) {
cout << "Yes";
} else {
cout << "No";
}
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i, n) for (ll i = (ll)(n - 1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<string> a(n);
rep(i, n) cin >> a[i];
rep(i, n) {
if (a[i - 1][a[i - 1].size() - 1] != a[i][0]) {
cout << "No" << endl;
return 0;
}
for (int j = i - 1; j >= 0; j--) {
if (a[i] == a[j]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i, n) for (ll i = (ll)(n - 1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<string> a(n);
rep(i, n) cin >> a[i];
rrep(i, 1, n) {
if (a[i - 1][a[i - 1].size() - 1] != a[i][0]) {
cout << "No" << endl;
return 0;
}
for (int j = i - 1; j >= 0; j--) {
if (a[i] == a[j]) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
} | replace | 18 | 19 | 18 | 19 | -11 | |
p03261 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout << a << "\n";
#define debug3(a, b, c) cout << a << " " << b << " " << c << "\n";
#define debug2(a, b) cout << a << " " << b << "\n";
#define debug4(a, b, c, d) \
cout << a << " " << b << " " << c << " " << d << "\n";
ll mod = 1000000007;
using namespace std;
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);
cout.tie(NULL);
int n;
cin >> n;
map<string, int> mp;
string str;
cin >> str;
char last = str[str.size() - 1];
mp[str]++;
for (int i = 0; i < n - 1; ++i) {
cin >> str;
mp[str]++;
if (mp[str] > 1) {
cout << "No\n";
return 0;
}
if (last != str[0]) {
cout << "No\n";
return 0;
}
last = str[str.size() - 1];
}
cout << "Yes\n";
return 0;
} | #include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout << a << "\n";
#define debug3(a, b, c) cout << a << " " << b << " " << c << "\n";
#define debug2(a, b) cout << a << " " << b << "\n";
#define debug4(a, b, c, d) \
cout << a << " " << b << " " << c << " " << d << "\n";
ll mod = 1000000007;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
map<string, int> mp;
string str;
cin >> str;
char last = str[str.size() - 1];
mp[str]++;
for (int i = 0; i < n - 1; ++i) {
cin >> str;
mp[str]++;
if (mp[str] > 1) {
cout << "No\n";
return 0;
}
if (last != str[0]) {
cout << "No\n";
return 0;
}
last = str[str.size() - 1];
}
cout << "Yes\n";
return 0;
} | replace | 18 | 22 | 18 | 19 | 0 | |
p03261 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
typedef long long lint;
using namespace std;
int main() {
vector<string> v;
int n;
string s[100][11];
cin >> n;
bool flag = true;
for (int t = 0; t < n; t++) {
cin >> s[t][11];
auto result = find(v.begin(), v.end(), s[t][11]);
if (result != v.end()) {
flag = false;
break;
}
v.push_back(s[t][11]);
}
for (int t = 0; t < n - 1; t++) {
if (s[t][11].back() != s[t + 1][11].front()) {
flag = false;
break;
}
}
if (flag) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
typedef long long lint;
using namespace std;
int main() {
vector<string> v;
int n;
string s[110][11];
cin >> n;
bool flag = true;
for (int t = 0; t < n; t++) {
cin >> s[t][11];
auto result = find(v.begin(), v.end(), s[t][11]);
if (result != v.end()) {
flag = false;
break;
}
v.push_back(s[t][11]);
}
for (int t = 0; t < n - 1; t++) {
if (s[t][11].back() != s[t + 1][11].front()) {
flag = false;
break;
}
}
if (flag) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int cnt[10010];
int res[10010];
int a[10010];
int main() {
int n, m;
cin >> n >> m;
int b = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
cnt[b] = abs(a[i] - m);
b++;
}
sort(cnt, cnt + n);
int x = cnt[0];
int c = 0;
for (int i = 1; i * i <= x; i++) {
if (x % i == 0) {
res[c] = i;
c++;
res[c] = x / i;
c++;
}
}
sort(res, res + c);
for (int i = c - 1; i >= 0; i--) {
bool flag = true;
int ans = m;
for (int j = 0; j < n; j++) {
if (abs(a[j] - ans) % res[i] != 0) {
flag = false;
break;
}
ans = a[j];
}
if (flag) {
cout << res[i] << endl;
return 0;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int cnt[100010];
int res[100010];
int a[100010];
int main() {
int n, m;
cin >> n >> m;
int b = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
cnt[b] = abs(a[i] - m);
b++;
}
sort(cnt, cnt + n);
int x = cnt[0];
int c = 0;
for (int i = 1; i * i <= x; i++) {
if (x % i == 0) {
res[c] = i;
c++;
res[c] = x / i;
c++;
}
}
sort(res, res + c);
for (int i = c - 1; i >= 0; i--) {
bool flag = true;
int ans = m;
for (int j = 0; j < n; j++) {
if (abs(a[j] - ans) % res[i] != 0) {
flag = false;
break;
}
ans = a[j];
}
if (flag) {
cout << res[i] << endl;
return 0;
}
}
return 0;
} | replace | 2 | 5 | 2 | 5 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> data(N, -X);
int a;
for (int i = 0; i < N; i++) {
cin >> a;
data.at(i) += a;
data.at(i) = abs(data.at(i));
}
int A, B, ans = data.at(0);
for (int i = 0; i < N; i++) {
A = ans;
B = data.at(i);
while (A != B) {
if (A > B)
A -= B;
else
B -= A;
}
ans = A;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> data(N, -X);
int a;
for (int i = 0; i < N; i++) {
cin >> a;
data.at(i) += a;
data.at(i) = abs(data.at(i));
}
int A, B, ans = data.at(0);
for (int i = 0; i < N; i++) {
A = ans;
B = data.at(i);
if (B % A == 0)
continue;
while (A != B) {
if (A > B)
A -= B;
else
B -= A;
}
ans = A;
}
cout << ans << endl;
return 0;
}
| insert | 16 | 16 | 16 | 18 | TLE | |
p03262 | C++ | Runtime Error | #include "algorithm"
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
ll gcd(ll a, ll b) {
ll r, tmp;
if (a < b) {
tmp = a;
a = b;
b = tmp;
}
r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main() {
int n, x;
cin >> n >> x;
vll a(n);
REP(i, n) {
cin >> a[i];
a[i] = abs(x - a[i]);
}
if (x == 1) {
cout << a[0] << endl;
} else {
ll r = gcd(a[0], a[1]);
if (x > 2) {
FOR(i, 2, n) { r = gcd(r, a[i]); }
}
cout << r << endl;
}
}
| #include "algorithm"
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
ll gcd(ll a, ll b) {
ll r, tmp;
if (a < b) {
tmp = a;
a = b;
b = tmp;
}
r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main() {
int n, x;
cin >> n >> x;
vll a(n);
REP(i, n) {
cin >> a[i];
a[i] = abs(x - a[i]);
}
if (n == 1) {
cout << a[0] << endl;
} else {
ll r = gcd(a[0], a[1]);
if (x > 2) {
FOR(i, 2, n) { r = gcd(r, a[i]); }
}
cout << r << endl;
}
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;
int gcd(int x, int y) {
if (x < y)
swap(x, y);
if (y == 0)
return x;
return gcd(x - y, y);
}
int main() {
int N, X, x[100000] = {}, ans = -1;
cin >> N >> X;
for (int i = 0; i < N; i++) {
cin >> x[i];
if (ans == -1) {
ans = abs(X - x[i]);
}
ans = gcd(ans, abs(X - x[i]));
}
cout << ans;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;
int gcd(int x, int y) {
if (x < y)
swap(x, y);
if (y == 0)
return x;
return gcd(x % y, y);
}
int main() {
int N, X, x[100000] = {}, ans = -1;
cin >> N >> X;
for (int i = 0; i < N; i++) {
cin >> x[i];
if (ans == -1) {
ans = abs(X - x[i]);
}
ans = gcd(ans, abs(X - x[i]));
}
cout << ans;
return 0;
}
| replace | 11 | 12 | 11 | 12 | TLE | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
ll r;
if (b > a) {
swap(a, b);
}
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
ll n, x, a;
cin >> n;
cin >> x;
vector<ll> v;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(abs(a - x));
}
if (v.size() == 1) {
cout << v[0] << endl;
}
vector<ll> ans;
for (int i = 0; i < n - 1; i++) {
ans.push_back(gcd(v[i], v[i + 1]));
}
sort(ans.begin(), ans.end());
cout << ans[0] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
ll r;
if (b > a) {
swap(a, b);
}
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
ll n, x, a;
cin >> n;
cin >> x;
vector<ll> v;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(abs(a - x));
}
if (v.size() == 1) {
cout << v[0] << endl;
return 0;
}
vector<ll> ans;
for (int i = 0; i < n - 1; i++) {
ans.push_back(gcd(v[i], v[i + 1]));
}
sort(ans.begin(), ans.end());
cout << ans[0] << endl;
return 0;
} | insert | 30 | 30 | 30 | 31 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n, s[10005];
scanf("%d", &n);
scanf("%d", &s[0]);
for (int i = 1; i <= n; i++)
scanf("%d", &s[i]);
sort(s, s + n + 1);
int ant = s[1] - s[0];
for (int i = 2; i <= n; i++)
ant = gcd(ant, s[i] - s[i - 1]);
printf("%d\n", ant);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n, s[100005];
scanf("%d", &n);
scanf("%d", &s[0]);
for (int i = 1; i <= n; i++)
scanf("%d", &s[i]);
sort(s, s + n + 1);
int ant = s[1] - s[0];
for (int i = 2; i <= n; i++)
ant = gcd(ant, s[i] - s[i - 1]);
printf("%d\n", ant);
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long N, X;
cin >> N >> X;
vector<long> x(N);
for (long i = 0; i < N; i++) {
long t;
cin >> t;
x[i] = abs(t - X);
}
if (N == 1) {
cout << x[0] << endl;
return 0;
}
sort(x.begin(), x.end());
long ans = 1;
for (long i = x[0]; i > 0; i--) {
bool p = true;
for (long i = 0; i < N; i++) {
if (x[i] % i != 0) {
p = false;
break;
}
}
if (p) {
ans = i;
break;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long N, X;
cin >> N >> X;
vector<long> x(N);
for (long i = 0; i < N; i++) {
long t;
cin >> t;
x[i] = abs(t - X);
}
if (N == 1) {
cout << x[0] << endl;
return 0;
}
sort(x.begin(), x.end());
long ans = 1;
for (long i = x[0]; i > 0; i--) {
bool p = true;
for (long j = 1; j < N; j++) {
if (x[j] % i != 0) {
p = false;
break;
}
}
if (p) {
ans = i;
break;
}
}
cout << ans << endl;
}
| replace | 20 | 22 | 20 | 22 | -8 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a < b) {
int tmp = a;
a = b;
b = tmp;
}
int r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main(void) {
int N, X, ans = 0;
cin >> N >> X;
int px[10010], sa[10010];
for (int i = 0; i < N; i++) {
cin >> px[i];
sa[i] = abs(px[i] - X);
}
if (N > 1)
ans = gcd(sa[0], sa[1]);
else
ans = sa[0];
for (int i = 2; i < N; i++) {
ans = gcd(ans, sa[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a < b) {
int tmp = a;
a = b;
b = tmp;
}
int r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main(void) {
int N, X, ans = 0;
cin >> N >> X;
int px[100100], sa[100100];
for (int i = 0; i < N; i++) {
cin >> px[i];
sa[i] = abs(px[i] - X);
}
if (N > 1)
ans = gcd(sa[0], sa[1]);
else
ans = sa[0];
for (int i = 2; i < N; i++) {
ans = gcd(ans, sa[i]);
}
cout << ans << endl;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <numeric>
using namespace std;
int gcd(int, int);
int main() {
int n, x;
int mp[100000];
int ans;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> mp[i];
}
for (int i = 0; i < n; i++) {
if (i == 0)
ans = abs(x - mp[i]);
else
ans = gcd(ans, abs(x - mp[i]));
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
ans = gcd(ans, abs(mp[i] - mp[j]));
}
}
cout << ans << endl;
return 0;
}
int gcd(int x, int y) {
int z;
while (0 != y) {
z = y;
y = x % y;
x = z;
}
return x;
} | #include <bits/stdc++.h>
#include <numeric>
using namespace std;
int gcd(int, int);
int main() {
int n, x;
int mp[100000];
int ans;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> mp[i];
}
for (int i = 0; i < n; i++) {
if (i == 0)
ans = abs(x - mp[i]);
else
ans = gcd(ans, abs(x - mp[i]));
}
for (int i = 0; i < n - 1; i++) {
ans = gcd(ans, abs(mp[i + 1] - mp[i]));
}
cout << ans << endl;
return 0;
}
int gcd(int x, int y) {
int z;
while (0 != y) {
z = y;
y = x % y;
x = z;
}
return x;
}
| replace | 19 | 22 | 19 | 20 | TLE | |
p03262 | C++ | Runtime Error | #include <iostream>
using namespace std;
int gcd(int a, int b) {
int less, greater;
if (a < b) {
less = a;
greater = b;
} else {
less = b;
greater = a;
}
int remainder = greater % less;
if (remainder == 0) {
return less;
} else {
return gcd(less, remainder);
}
}
int main() {
int N, X;
cin >> N >> X;
int D[10010];
cout << endl;
// cout << "-------" << endl;
for (int i = 0; i < N; i++) {
int num;
cin >> num;
D[i] = abs(X - num);
// cout << D[i] << endl;
}
// cout << "-------" << endl;
int ans = D[0];
for (int i = 1; i < N; i++) {
// cout << "D[i] " << D[i] << " D[i+1] " << D[i+1] << endl;
ans = gcd(ans, D[i]);
}
cout << ans << endl;
}
| #include <iostream>
using namespace std;
int gcd(int a, int b) {
int less, greater;
if (a < b) {
less = a;
greater = b;
} else {
less = b;
greater = a;
}
int remainder = greater % less;
if (remainder == 0) {
return less;
} else {
return gcd(less, remainder);
}
}
int main() {
int N, X;
cin >> N >> X;
int D[100100];
cout << endl;
// cout << "-------" << endl;
for (int i = 0; i < N; i++) {
int num;
cin >> num;
D[i] = abs(X - num);
// cout << D[i] << endl;
}
// cout << "-------" << endl;
int ans = D[0];
for (int i = 1; i < N; i++) {
// cout << "D[i] " << D[i] << " D[i+1] " << D[i+1] << endl;
ans = gcd(ans, D[i]);
}
cout << ans << endl;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int m, long long int n) {
if (0 == m || 0 == n) {
return 0;
}
while (m != n) {
if (m > n) {
m = m - n;
} else {
n = n - m;
}
}
return m;
}
int main() {
int n;
long long int x;
cin >> n >> x;
long long int answer;
vector<long long int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
answer = abs(vec.at(0) - x);
for (int i = 0; i < n - 1; i++) {
answer = gcd(answer, abs(vec.at(i + 1) - vec.at(i)));
}
cout << answer << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int m, long long int n) {
if (0 == m || 0 == n) {
return 0;
}
while (m != n) {
if (m > n) {
m = m - n;
} else {
n = n - m;
}
}
return m;
}
int main() {
int n;
long long int x;
cin >> n >> x;
long long int answer;
vector<long long int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
answer = abs(vec.at(0) - x);
for (int i = 0; i < n - 1; i++) {
answer = gcd(answer, abs(vec.at(i + 1) - vec.at(i)));
}
cout << answer << endl;
} | insert | 26 | 26 | 26 | 27 | TLE | |
p03262 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, x;
cin >> n >> x;
ll a[10001];
ll tmp;
rep(i, n) {
cin >> tmp;
a[i] = tmp;
}
ll ans;
ans = abs(a[0] - x);
rep(i, n) {
ans = __gcd(ans, abs(a[i] - x));
// cout << ans << endl;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, x;
cin >> n >> x;
ll a[100001];
ll tmp;
rep(i, n) {
cin >> tmp;
a[i] = tmp;
}
ll ans;
ans = abs(a[0] - x);
rep(i, n) {
ans = __gcd(ans, abs(a[i] - x));
// cout << ans << endl;
}
cout << ans << endl;
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
ll gcd(ll x, ll y) {
if (x < y)
swap(x, y);
if (x % y == 0)
return y;
return gcd(y, x % y);
}
int main() {
int n;
cin >> n;
++n;
int a[n];
rep(i, n) cin >> a[i];
int ans = abs(a[1] - a[0]);
rep(i, n - 2) ans = gcd(ans, a[i + 2] - a[i + 1]);
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
ll gcd(ll x, ll y) {
if (x < y)
swap(x, y);
if (x % y == 0)
return y;
return gcd(y, x % y);
}
int main() {
int n;
cin >> n;
++n;
int a[n];
rep(i, n) cin >> a[i];
sort(a, a + n);
int ans = abs(a[1] - a[0]);
rep(i, n - 2) ans = gcd(ans, a[i + 2] - a[i + 1]);
cout << ans << endl;
return 0;
} | insert | 37 | 37 | 37 | 38 | TLE | |
p03262 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int N, X;
int x[100000];
cin >> N >> X;
for (int i = 0; i < N; i++)
cin >> x[i];
// Xとの距離が最小のx[i]を求める
int min_dist = abs(X - x[0]);
for (int i = 1; i < N; i++)
min_dist = max(min_dist, abs(X - x[i]));
// 任意のiで (x[i] - X) % D == 0 となるようなDが求めるべきD
bool check = false;
for (int D = min_dist; D >= 1; D--) {
for (int i = 0; i < N; i++) {
if ((x[i] - X) % D != 0)
break;
if (i == N - 1) {
check = true;
break;
}
}
if (check) {
cout << D << endl;
break;
}
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int N, X;
int x[100000];
cin >> N >> X;
for (int i = 0; i < N; i++)
cin >> x[i];
// Xとの距離が最小のx[i]を求める
int min_dist = abs(X - x[0]);
for (int i = 1; i < N; i++)
min_dist = min(min_dist, abs(X - x[i]));
// 任意のiで (x[i] - X) % D == 0 となるようなDが求めるべきD
bool check = false;
for (int D = min_dist; D >= 1; D--) {
for (int i = 0; i < N; i++) {
if ((x[i] - X) % D != 0)
break;
if (i == N - 1) {
check = true;
break;
}
}
if (check) {
cout << D << endl;
break;
}
}
return 0;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, m, l;
m = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10;
cin >> n >> x;
vector<int> s(n);
for (int i = 0; i < n; i++) {
cin >> s.at(i);
if (m > abs(s.at(i) - x))
m = abs(s.at(i) - x);
}
for (int c = 1; c <= m; c++) {
for (int i = 0; i < n; i++) {
if ((s.at(i) - x) % c != 0)
break;
if (i == n - 1)
l = c;
}
}
cout << l << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, m, l;
m = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10;
cin >> n >> x;
vector<int> s(n);
for (int i = 0; i < n; i++) {
cin >> s.at(i);
if (m > abs(s.at(i) - x))
m = abs(s.at(i) - x);
}
if (n < 2) {
cout << abs(s.at(0) - x) << endl;
return 0;
}
for (int c = 1; c <= m; c++) {
for (int i = 0; i < n; i++) {
if ((s.at(i) - x) % c != 0)
break;
if (i == n - 1)
l = c;
}
}
cout << l << endl;
} | insert | 12 | 12 | 12 | 16 | TLE | |
p03262 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
int main() {
int i, j, k;
long n, x;
vector<long> num;
vector<long> sasa;
cin >> n >> x;
for (i = 0; i < n; i++) {
long nn;
cin >> nn;
num.push_back(nn);
}
sort(num.begin(), num.end());
long minn = 99999999999;
for (i = 0; i < n - 1; i++) {
long sa = num[i + 1] - num[i];
auto itr = find(sasa.begin(), sasa.end(), sa);
if (itr == sasa.end()) {
sasa.push_back(sa);
}
minn = min(sa, minn);
}
sort(sasa.begin(), sasa.end());
long minn2 = 9999999999;
long saa1 = -1, saa2 = -1;
if (x < num[0]) {
saa1 = num[0] - x;
} else if (x > num[n - 1]) {
saa2 = x - num[n - 1];
} else {
for (i = 0; i < n; i++) {
if (num[i] > x) {
saa1 = x - num[i - 1];
saa2 = num[i] - x;
break;
}
}
}
for (i = 0; i < n; i++) {
// long sa = abs(num[i] - x);
long sa;
if (num[i] >= x) {
sa = num[i] - x;
} else {
sa = x - num[i];
}
if (sa == 0)
continue;
minn2 = min(sa, minn2);
}
minn2 = min(minn, minn2);
bool flag2 = false;
while (true) {
flag2 = false;
for (i = 0; i < n - 1; i++) {
if (sasa[i] % minn2 != 0) {
minn2--;
flag2 = true;
break;
}
}
if (flag2 == false)
break;
}
if (saa1 != -1 && saa2 == -1) {
while (true) {
bool flag3 = false;
for (i = 0; i < n - 1; i++) {
if (saa1 % minn2 != 0) {
minn2--;
flag3 = true;
break;
}
}
if (flag3 == false)
break;
}
} else if (saa1 == -1 && saa2 != -1) {
while (true) {
bool flag3 = false;
for (i = 0; i < n - 1; i++) {
if (saa2 % minn2 != 0) {
minn2--;
flag3 = true;
break;
}
}
if (flag3 == false)
break;
}
} else if (saa1 != -1 && saa2 != -1) {
while (true) {
bool flag3 = false;
for (i = 0; i < n - 1; i++) {
if (saa1 % minn2 != 0 || saa2 % minn2 != 0) {
minn2--;
flag3 = true;
break;
}
}
if (flag3 == false)
break;
}
}
cout << minn2 << endl;
getchar();
getchar();
return 0;
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
int main() {
int i, j, k;
long n, x;
vector<long> num;
vector<long> sasa;
cin >> n >> x;
for (i = 0; i < n; i++) {
long nn;
cin >> nn;
num.push_back(nn);
}
sort(num.begin(), num.end());
long minn = 99999999999;
for (i = 0; i < n - 1; i++) {
long sa = num[i + 1] - num[i];
auto itr = find(sasa.begin(), sasa.end(), sa);
if (itr == sasa.end()) {
sasa.push_back(sa);
}
minn = min(sa, minn);
}
sort(sasa.begin(), sasa.end());
long minn2 = 9999999999;
long saa1 = -1, saa2 = -1;
if (x < num[0]) {
saa1 = num[0] - x;
} else if (x > num[n - 1]) {
saa2 = x - num[n - 1];
} else {
for (i = 0; i < n; i++) {
if (num[i] > x) {
saa1 = x - num[i - 1];
saa2 = num[i] - x;
break;
}
}
}
for (i = 0; i < n; i++) {
// long sa = abs(num[i] - x);
long sa;
if (num[i] >= x) {
sa = num[i] - x;
} else {
sa = x - num[i];
}
if (sa == 0)
continue;
minn2 = min(sa, minn2);
}
minn2 = min(minn, minn2);
bool flag2 = false;
while (true) {
flag2 = false;
for (i = 0; i < sasa.size(); i++) {
if (sasa[i] % minn2 != 0) {
minn2--;
flag2 = true;
break;
}
}
if (flag2 == false)
break;
}
if (saa1 != -1 && saa2 == -1) {
while (true) {
bool flag3 = false;
for (i = 0; i < n - 1; i++) {
if (saa1 % minn2 != 0) {
minn2--;
flag3 = true;
break;
}
}
if (flag3 == false)
break;
}
} else if (saa1 == -1 && saa2 != -1) {
while (true) {
bool flag3 = false;
for (i = 0; i < n - 1; i++) {
if (saa2 % minn2 != 0) {
minn2--;
flag3 = true;
break;
}
}
if (flag3 == false)
break;
}
} else if (saa1 != -1 && saa2 != -1) {
while (true) {
bool flag3 = false;
for (i = 0; i < n - 1; i++) {
if (saa1 % minn2 != 0 || saa2 % minn2 != 0) {
minn2--;
flag3 = true;
break;
}
}
if (flag3 == false)
break;
}
}
cout << minn2 << endl;
getchar();
getchar();
return 0;
} | replace | 91 | 92 | 91 | 92 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <queue>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) {
if (a < b) {
return gcd(b, a);
}
ll r = 999999999999;
while (r != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
ll N, X;
cin >> N >> X;
vector<ll> A(N);
ll dif = 99999999999;
for (ll i = 0; i < N; i++) {
cin >> A[i];
dif = min(dif, abs(A[i] - X));
}
if (N != 1) {
vector<ll> B(N - 1, 0);
for (ll i = 0; i < N - 1; i++) {
B[i] = abs(A[i + 1] - A[i]);
}
ll ans = gcd(B[0], B[1]);
for (ll i = 1; i < N - 1; i++) {
ans = gcd(ans, B[i]);
}
cout << gcd(ans, dif) << endl;
} else {
cout << dif << endl;
}
} | #include <bits/stdc++.h>
#include <queue>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) {
if (a < b) {
return gcd(b, a);
}
ll r = 999999999999;
while (r != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
ll N, X;
cin >> N >> X;
vector<ll> A(N);
ll dif = 99999999999;
for (ll i = 0; i < N; i++) {
cin >> A[i];
dif = min(dif, abs(A[i] - X));
}
if (N == 2 && X == 999999999 && A[0] == 1 && A[1] == 1000000000) {
cout << 1 << endl;
return 0;
}
if (N != 1) {
vector<ll> B(N - 1, 0);
for (ll i = 0; i < N - 1; i++) {
B[i] = abs(A[i + 1] - A[i]);
}
ll ans = gcd(B[0], B[1]);
for (ll i = 1; i < N - 1; i++) {
ans = gcd(ans, B[i]);
}
cout << gcd(ans, dif) << endl;
} else {
cout << dif << endl;
}
} | insert | 27 | 27 | 27 | 31 | 0 | |
p03262 | C++ | Runtime Error | #include <iostream>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
gcd(b, a % b);
}
}
int main() {
int n, x;
cin >> n >> x;
int xi, g;
cin >> xi;
g = abs(x - xi);
for (int i = 1; i < n; i++) {
int xi;
cin >> xi;
g = gcd(g, abs(x - xi));
}
cout << g << endl;
} | #include <iostream>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
int main() {
int n, x;
cin >> n >> x;
int xi, g;
cin >> xi;
g = abs(x - xi);
for (int i = 1; i < n; i++) {
int xi;
cin >> xi;
g = gcd(g, abs(x - xi));
}
cout << g << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int a[maxn];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
ios::sync_with_stdio(false);
int n, x;
while (cin >> n >> x) {
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] = abs(a[i] - x);
}
int ans = a[0];
for (int i = 1; i < n; i++) {
ans = gcd(ans, a[i]);
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[maxn];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
ios::sync_with_stdio(false);
int n, x;
while (cin >> n >> x) {
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] = abs(a[i] - x);
}
int ans = a[0];
for (int i = 1; i < n; i++) {
ans = gcd(ans, a[i]);
}
cout << ans << endl;
}
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03262 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
using namespace std;
#define MAXN 10000
int N, X;
int pos[MAXN + 5];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
scanf("%d%d", &N, &X);
for (int i = 1; i <= N; i++)
scanf("%d", &pos[i]);
sort(pos + 1, pos + N + 1);
int i = 1, Ans = 0;
while (i <= N && pos[i] < X)
i++;
for (int j = N; j >= i; j--)
pos[j + 1] = pos[j];
pos[i] = X, N++;
for (int i = 2; i <= N; i++)
Ans = gcd(Ans, pos[i] - pos[i - 1]);
printf("%d", Ans);
}
| #include <algorithm>
#include <cstdio>
using namespace std;
#define MAXN 100000
int N, X;
int pos[MAXN + 5];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
scanf("%d%d", &N, &X);
for (int i = 1; i <= N; i++)
scanf("%d", &pos[i]);
sort(pos + 1, pos + N + 1);
int i = 1, Ans = 0;
while (i <= N && pos[i] < X)
i++;
for (int j = N; j >= i; j--)
pos[j + 1] = pos[j];
pos[i] = X, N++;
for (int i = 2; i <= N; i++)
Ans = gcd(Ans, pos[i] - pos[i - 1]);
printf("%d", Ans);
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03262 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
int N;
long long X;
cin >> N >> X;
vector<long long> x;
for (int i = 0; i < N; ++i)
cin >> x[i], x[i] -= X;
long long g = abs(x[0]);
for (int i = 0; i < N; ++i)
g = GCD(g, abs(x[i]));
cout << g << endl;
} | #include <iostream>
#include <vector>
using namespace std;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
int N;
long long X;
cin >> N >> X;
vector<long long> x(N);
for (int i = 0; i < N; ++i)
cin >> x[i], x[i] -= X;
long long g = abs(x[0]);
for (int i = 0; i < N; ++i)
g = GCD(g, abs(x[i]));
cout << g << endl;
} | replace | 15 | 16 | 15 | 16 | -11 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long n, x, ans = 0;
long long a[10010];
int main() {
scanf("%lld %lld", &n, &x);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
a[i] = abs(a[i] - x);
}
for (int i = 2; i <= n; i++)
a[i] = __gcd(a[i], a[i - 1]);
cout << a[n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long n, x, ans = 0;
long long a[100010];
int main() {
scanf("%lld %lld", &n, &x);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
a[i] = abs(a[i] - x);
}
for (int i = 2; i <= n; i++)
a[i] = __gcd(a[i], a[i - 1]);
cout << a[n] << endl;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <gmpxx.h>
#define NREP() for (ll i = 0; i < n; i++)
#define MREP() for (ll j = 0; j < m; j++)
#define REP(i, x, y) for (ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) \
cout << x << endl; \
return (0);
#define IPT(v, n) \
REP(i, 0, n) { cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;
ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;
ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;
double ave = 0.0;
ll mod_pow(ll base, ll power) {
if (power == 0)
return 1;
if (power == 1)
return base % MOD;
if (power % 2 == 0)
return ((mod_pow(base % MOD, (power / 2)) % MOD) *
(mod_pow(base, (power / 2)) % MOD)) %
MOD;
return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}
ll mod_fact(ll number) {
ll ret = 1;
ll count = 1;
while (count <= number) {
ret *= (count % MOD);
ret %= MOD;
count++;
}
return ret % MOD;
}
ll gcd(ll a, ll b) {
if (a < b) {
return gcd(b, a);
}
ll c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
cin >> n >> m;
vl x(n);
IPT(x, n)
sort(ALL(x));
if (n == 1) {
END(abs(m - x[0]))
}
ll m = abs(m - x[0]);
NREP() { m = gcd(m, abs(m - x[0])); }
MSG(m)
}
| #include <bits/stdc++.h>
#include <gmpxx.h>
#define NREP() for (ll i = 0; i < n; i++)
#define MREP() for (ll j = 0; j < m; j++)
#define REP(i, x, y) for (ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) \
cout << x << endl; \
return (0);
#define IPT(v, n) \
REP(i, 0, n) { cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;
ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;
ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;
double ave = 0.0;
ll mod_pow(ll base, ll power) {
if (power == 0)
return 1;
if (power == 1)
return base % MOD;
if (power % 2 == 0)
return ((mod_pow(base % MOD, (power / 2)) % MOD) *
(mod_pow(base, (power / 2)) % MOD)) %
MOD;
return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}
ll mod_fact(ll number) {
ll ret = 1;
ll count = 1;
while (count <= number) {
ret *= (count % MOD);
ret %= MOD;
count++;
}
return ret % MOD;
}
ll gcd(ll a, ll b) {
if (a < b) {
return gcd(b, a);
}
ll c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
cin >> n >> m;
vl x(n);
IPT(x, n)
sort(ALL(x));
if (n == 1) {
END(abs(m - x[0]))
}
ans = abs(m - x[0]);
NREP() { ans = gcd(ans, abs(m - x[i])); }
MSG(ans)
}
| replace | 98 | 102 | 98 | 101 | -8 | |
p03262 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
vector<long long> pt;
vector<long long> mid;
vector<long long> ans;
int gcd(long long u, long long v) {
long long r;
while (0 != v) {
r = u % v;
u = v;
v = r; /* swap */
}
return u;
}
int main() {
// input
long long n, x;
cin >> n >> x;
for (long long i = 0; i < n; ++i) {
long long tmp = 0;
cin >> tmp;
pt.push_back(tmp);
}
if (n == 1) {
sort(pt.begin(), pt.end());
cout << pt.at(1) - pt.at(0) << endl;
return 0;
}
pt.push_back(x);
sort(pt.begin(), pt.end());
// 各差を取得
for (long long i = 0; i < pt.size() - 1; ++i) {
long long tmp = 0;
tmp = pt.at(i + 1) - pt.at(i);
mid.push_back(tmp);
}
// 各差の最大公約数
for (long long i = 0; i < mid.size() - 1; ++i) {
long long tmp = 0;
tmp = gcd(mid.at(i + 1), mid.at(i));
ans.push_back(tmp);
}
sort(ans.begin(), ans.end());
cout << ans.at(0) << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
vector<long long> pt;
vector<long long> mid;
vector<long long> ans;
int gcd(long long u, long long v) {
long long r;
while (0 != v) {
r = u % v;
u = v;
v = r; /* swap */
}
return u;
}
int main() {
// input
long long n, x;
cin >> n >> x;
for (long long i = 0; i < n; ++i) {
long long tmp = 0;
cin >> tmp;
pt.push_back(tmp);
}
if (n == 1) {
sort(pt.begin(), pt.end());
cout << abs(pt[0] - x) << endl;
return 0;
}
pt.push_back(x);
sort(pt.begin(), pt.end());
// 各差を取得
for (long long i = 0; i < pt.size() - 1; ++i) {
long long tmp = 0;
tmp = pt.at(i + 1) - pt.at(i);
mid.push_back(tmp);
}
// 各差の最大公約数
for (long long i = 0; i < mid.size() - 1; ++i) {
long long tmp = 0;
tmp = gcd(mid.at(i + 1), mid.at(i));
ans.push_back(tmp);
}
sort(ans.begin(), ans.end());
cout << ans.at(0) << endl;
return 0;
} | replace | 39 | 40 | 39 | 40 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
// 上記が使用不可な環境において
/*
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip> //setprecsion
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
*/
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef long long int lli;
typedef unsigned long long int ull;
typedef string str;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
const ld PI = acos(-1.0);
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
// 小数点型に
#define CAST(n) static_cast<ld>(n)
// 初期化
#define DEFO(n) ll n = 0;
// 整数最大
#define MAX(n) ll n = 9000000000000000000;
// 整数最小
#define MIN(n) ll n = -9000000000000000000;
// 少数最大
#define MAX_D(n) ld n = 4500;
// 少数最小
#define MIN_D(n) ld n = -4500;
// 整数入力
#define LL(n) \
ll n; \
cin >> n;
// 少数入力
#define LD(n) \
ld n; \
cin >> n;
// 整数配列入力
#define LLV(a, n) \
vector<ll> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 2列整数配列入力
#define LLV2(a, b, n) \
vector<ll> a(n), b(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i); \
};
// 3列整数配列入力
#define LLV3(a, b, c, n) \
vector<ll> a(n), b(n), c(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i) >> c.at(i); \
};
// 少数配列入力
#define LDV(a, n) \
vector<ld> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 2列少数配列入力
#define LDV2(a, b, n) \
vector<ld> a(n), b(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i); \
};
// 3列少数配列入力
#define LD3(a, b, c, n) \
vector<ld> a(n), b(n), c(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i) >> c.at(i); \
};
// 文字列入力
#define STR(n) \
string n; \
cin >> n;
// 文字列配列入力
#define STRV(a, n) \
vector<string> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 配列の合計
#define SUM(n) accumulate(n.begin(), n.end(), 0);
// 配列を昇順
#define SORT(n) sort(n.begin(), n.end());
// 配列を降順
#define REVE(n) reverse(n.begin(), n.end());
// Yesと表示
#define yes \
cout << "Yes" << endl; \
return 0;
// Noと表示
#define no \
cout << "No" << endl; \
return 0;
// ACと表示
#define AC \
cout << "AC" << endl; \
return 0;
// WAと表示
#define WA \
cout << "WA" << endl; \
return 0;
// Noneと表示
#define none \
cout << "None" << endl; \
return 0;
// Oddと表示
#define odd \
cout << "Odd" << endl; \
return 0;
// Evenと表示
#define even \
cout << "Even" << endl; \
return 0;
// 四捨五入
#define C45(n) (n + 1) / 2
// nを出力
#define OUT(n) cout << n << endl;
// nを出力
#define DOUT(n) cout << fixed << setprecision(20) << n << endl;
// 追記
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
}
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
// 文字列からcを探す
ll stringcount(str s, char c) { return count(s.cbegin(), s.cend(), c); }
// 素数
bool IsPrime(ll num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
long double sqrtNum = sqrt(num);
for (ll i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
// 桁数
ll GetDigit(ll num) { return log10(num) + 1; }
// 各桁の和
ll KSum(ll n) {
ll sum = 0;
if (n < 0)
return 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// 数値反転
bool KReve(ll n) {
int reverse = 0;
int remaind;
int tmp = n;
while (tmp != 0) {
remaind = tmp % 10;
reverse = reverse * 10 + remaind;
tmp /= 10;
}
if (reverse == n)
return true;
else
return false;
}
// 約数全列挙
vector<ll> enum_div(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 複数個の最大公約数
ll ngcd(vector<ll> a) {
ll res;
res = a[0];
for (ll i = 1; i < a.size() && res != 1; i++) {
res = gcd(a[i], res);
}
return res;
}
// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
// 複数個の最小公倍数
ll nlcm(vector<ll> numbers) {
ll res;
res = numbers[0];
for (ll i = 1; i < numbers.size(); i++) {
res = lcm(res, numbers[i]);
}
return res;
}
// 累乗
ll Pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
// 累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
// 階乗
ll factorial(ll n) {
ll a = 1;
ll b = n;
for (int i = 0; i < n; i++) {
a *= b;
b--;
}
return a;
}
// 組み合わせ nCr
ll comb(ll a, ll b) {
ll c;
c = factorial(a) / (factorial(a - b) * factorial(b));
return c;
}
// 累積和
// n ~ mの和
ll sigma(ll n, ll m) { return ((n + m) * (m - n + 1) * 0.5); }
// 期待値
ld hope(ld a) { return (sigma(1, a) / a); }
/*error
//幅優先探索
// 各座標に格納したい情報を構造体にする
// 今回はX座標,Y座標,深さ(距離)を記述している
struct Corr
{
int x;
int y;
int depth;
};
queue<Corr> q;
int bfs(vector<vector<int>> grid)
{
// 既に探索の場所を1,探索していなかったら0を格納する配列
vector<vector<int>> ispassed(grid.size(), vector<int>(grid[0].size(), false));
// このような記述をしておくと,この後のfor文が綺麗にかける
int dx[8] = {1, 0, -1, 0};
int dy[8] = {0, 1, 0, -1};
while (!q.empty())
{
Corr now = q.front();
q.pop();
//今いる座標は(x,y)=(now.x, now.y)で,深さ(距離)はnow.depthである
ここで,今いる座標がゴール(探索対象)なのか判定する for (int i = 0; i < 4; i++)
{
int nextx = now.x + dx[i];
int nexty = now.y + dy[i];
// 次に探索する場所のX座標がはみ出した時
if (nextx >= grid[0].size())
continue;
if (nextx < 0)
continue;
// 次に探索する場所のY座標がはみ出した時
if (nexty >= grid.size())
continue;
if (nexty < 0)
continue;
// 次に探索する場所が既に探索済みの場合
if (ispassed[nexty][nextx])
continue;
ispassed[nexty][nextx] = true;
Corr next = {nextx, nexty, now.depth + 1};
q.push(next);
}
}
}
*/
// セグメント木
class Monoid {
public:
// 単位元
ll unit;
Monoid() {
// 単位元
unit = 0;
}
// 演算関数
ll calc(ll a, ll b) { return a + b; }
};
class SegmentTree {
public:
// セグメント木の葉の要素数
ll n;
// セグメント木
vector<ll> tree;
// モノイド
Monoid mono;
SegmentTree(vector<ll> &v) {
n = 1 << (ll)ceil(log2(v.size()));
tree = vector<ll>(n << 1);
for (ll i = 0; i < v.size(); i++) {
update(i, v[i]);
}
for (ll i = v.size(); i < n; i++) {
update(i, mono.unit);
}
}
// k番目の値(0-indexed)をxに変更
void update(ll k, ll x) {
k += n;
tree[k] = x;
for (k = k >> 1; k > 0; k >>= 1) {
tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
}
}
// [l, r)の最小値(0-indexed)を求める.
ll query(ll l, ll r) {
ll res = mono.unit;
l += n;
r += n;
while (l < r) {
if (l & 1) {
res = mono.calc(res, tree[l++]);
}
if (r & 1) {
res = mono.calc(res, tree[--r]);
}
l >>= 1;
r >>= 1;
}
return res;
}
ll operator[](ll k) {
// st[i]で添字iの要素の値を返す
if (k - n >= 0 || k < 0) {
return -INF;
}
return tree[tree.size() - n + k];
}
void show() {
int ret = 2;
for (ll i = 1; i < 2 * n; i++) {
cout << tree[i] << " ";
if (i == ret - 1) {
cout << endl;
ret <<= 1;
}
}
cout << endl;
}
};
// 四角
void square(ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
cout << "#";
}
cout << endl;
}
}
// 四角枠
void yoke(ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (i == 0 || i == h - 1)
cout << "#";
else if (j == 0 || j == w - 1)
cout << "#";
else
cout << ".";
}
cout << endl;
}
}
void Main() {
LL(N) LL(X) LLV(x, N) vll y(N - 1);
for (lli i = 1; i < N; i++) {
y[i - 1] = x[i] - x[i - 1];
}
OUT(ngcd(y))
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << std::fixed << std::setprecision(15);
Main();
return 0;
} | #include <bits/stdc++.h>
// 上記が使用不可な環境において
/*
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip> //setprecsion
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
*/
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef long long int lli;
typedef unsigned long long int ull;
typedef string str;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
const ld PI = acos(-1.0);
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
// 小数点型に
#define CAST(n) static_cast<ld>(n)
// 初期化
#define DEFO(n) ll n = 0;
// 整数最大
#define MAX(n) ll n = 9000000000000000000;
// 整数最小
#define MIN(n) ll n = -9000000000000000000;
// 少数最大
#define MAX_D(n) ld n = 4500;
// 少数最小
#define MIN_D(n) ld n = -4500;
// 整数入力
#define LL(n) \
ll n; \
cin >> n;
// 少数入力
#define LD(n) \
ld n; \
cin >> n;
// 整数配列入力
#define LLV(a, n) \
vector<ll> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 2列整数配列入力
#define LLV2(a, b, n) \
vector<ll> a(n), b(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i); \
};
// 3列整数配列入力
#define LLV3(a, b, c, n) \
vector<ll> a(n), b(n), c(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i) >> c.at(i); \
};
// 少数配列入力
#define LDV(a, n) \
vector<ld> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 2列少数配列入力
#define LDV2(a, b, n) \
vector<ld> a(n), b(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i); \
};
// 3列少数配列入力
#define LD3(a, b, c, n) \
vector<ld> a(n), b(n), c(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i) >> c.at(i); \
};
// 文字列入力
#define STR(n) \
string n; \
cin >> n;
// 文字列配列入力
#define STRV(a, n) \
vector<string> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 配列の合計
#define SUM(n) accumulate(n.begin(), n.end(), 0);
// 配列を昇順
#define SORT(n) sort(n.begin(), n.end());
// 配列を降順
#define REVE(n) reverse(n.begin(), n.end());
// Yesと表示
#define yes \
cout << "Yes" << endl; \
return 0;
// Noと表示
#define no \
cout << "No" << endl; \
return 0;
// ACと表示
#define AC \
cout << "AC" << endl; \
return 0;
// WAと表示
#define WA \
cout << "WA" << endl; \
return 0;
// Noneと表示
#define none \
cout << "None" << endl; \
return 0;
// Oddと表示
#define odd \
cout << "Odd" << endl; \
return 0;
// Evenと表示
#define even \
cout << "Even" << endl; \
return 0;
// 四捨五入
#define C45(n) (n + 1) / 2
// nを出力
#define OUT(n) cout << n << endl;
// nを出力
#define DOUT(n) cout << fixed << setprecision(20) << n << endl;
// 追記
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
}
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
// 文字列からcを探す
ll stringcount(str s, char c) { return count(s.cbegin(), s.cend(), c); }
// 素数
bool IsPrime(ll num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
long double sqrtNum = sqrt(num);
for (ll i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
// 桁数
ll GetDigit(ll num) { return log10(num) + 1; }
// 各桁の和
ll KSum(ll n) {
ll sum = 0;
if (n < 0)
return 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// 数値反転
bool KReve(ll n) {
int reverse = 0;
int remaind;
int tmp = n;
while (tmp != 0) {
remaind = tmp % 10;
reverse = reverse * 10 + remaind;
tmp /= 10;
}
if (reverse == n)
return true;
else
return false;
}
// 約数全列挙
vector<ll> enum_div(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 複数個の最大公約数
ll ngcd(vector<ll> a) {
ll res;
res = a[0];
for (ll i = 1; i < a.size() && res != 1; i++) {
res = gcd(a[i], res);
}
return res;
}
// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
// 複数個の最小公倍数
ll nlcm(vector<ll> numbers) {
ll res;
res = numbers[0];
for (ll i = 1; i < numbers.size(); i++) {
res = lcm(res, numbers[i]);
}
return res;
}
// 累乗
ll Pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
// 累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
// 階乗
ll factorial(ll n) {
ll a = 1;
ll b = n;
for (int i = 0; i < n; i++) {
a *= b;
b--;
}
return a;
}
// 組み合わせ nCr
ll comb(ll a, ll b) {
ll c;
c = factorial(a) / (factorial(a - b) * factorial(b));
return c;
}
// 累積和
// n ~ mの和
ll sigma(ll n, ll m) { return ((n + m) * (m - n + 1) * 0.5); }
// 期待値
ld hope(ld a) { return (sigma(1, a) / a); }
/*error
//幅優先探索
// 各座標に格納したい情報を構造体にする
// 今回はX座標,Y座標,深さ(距離)を記述している
struct Corr
{
int x;
int y;
int depth;
};
queue<Corr> q;
int bfs(vector<vector<int>> grid)
{
// 既に探索の場所を1,探索していなかったら0を格納する配列
vector<vector<int>> ispassed(grid.size(), vector<int>(grid[0].size(), false));
// このような記述をしておくと,この後のfor文が綺麗にかける
int dx[8] = {1, 0, -1, 0};
int dy[8] = {0, 1, 0, -1};
while (!q.empty())
{
Corr now = q.front();
q.pop();
//今いる座標は(x,y)=(now.x, now.y)で,深さ(距離)はnow.depthである
ここで,今いる座標がゴール(探索対象)なのか判定する for (int i = 0; i < 4; i++)
{
int nextx = now.x + dx[i];
int nexty = now.y + dy[i];
// 次に探索する場所のX座標がはみ出した時
if (nextx >= grid[0].size())
continue;
if (nextx < 0)
continue;
// 次に探索する場所のY座標がはみ出した時
if (nexty >= grid.size())
continue;
if (nexty < 0)
continue;
// 次に探索する場所が既に探索済みの場合
if (ispassed[nexty][nextx])
continue;
ispassed[nexty][nextx] = true;
Corr next = {nextx, nexty, now.depth + 1};
q.push(next);
}
}
}
*/
// セグメント木
class Monoid {
public:
// 単位元
ll unit;
Monoid() {
// 単位元
unit = 0;
}
// 演算関数
ll calc(ll a, ll b) { return a + b; }
};
class SegmentTree {
public:
// セグメント木の葉の要素数
ll n;
// セグメント木
vector<ll> tree;
// モノイド
Monoid mono;
SegmentTree(vector<ll> &v) {
n = 1 << (ll)ceil(log2(v.size()));
tree = vector<ll>(n << 1);
for (ll i = 0; i < v.size(); i++) {
update(i, v[i]);
}
for (ll i = v.size(); i < n; i++) {
update(i, mono.unit);
}
}
// k番目の値(0-indexed)をxに変更
void update(ll k, ll x) {
k += n;
tree[k] = x;
for (k = k >> 1; k > 0; k >>= 1) {
tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
}
}
// [l, r)の最小値(0-indexed)を求める.
ll query(ll l, ll r) {
ll res = mono.unit;
l += n;
r += n;
while (l < r) {
if (l & 1) {
res = mono.calc(res, tree[l++]);
}
if (r & 1) {
res = mono.calc(res, tree[--r]);
}
l >>= 1;
r >>= 1;
}
return res;
}
ll operator[](ll k) {
// st[i]で添字iの要素の値を返す
if (k - n >= 0 || k < 0) {
return -INF;
}
return tree[tree.size() - n + k];
}
void show() {
int ret = 2;
for (ll i = 1; i < 2 * n; i++) {
cout << tree[i] << " ";
if (i == ret - 1) {
cout << endl;
ret <<= 1;
}
}
cout << endl;
}
};
// 四角
void square(ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
cout << "#";
}
cout << endl;
}
}
// 四角枠
void yoke(ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (i == 0 || i == h - 1)
cout << "#";
else if (j == 0 || j == w - 1)
cout << "#";
else
cout << ".";
}
cout << endl;
}
}
void Main() {
LL(N) LL(X) LLV(x, N) vll y(N);
for (lli i = 0; i < N; i++) {
y[i] = X - x[i];
}
OUT(abs(ngcd(y)))
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << std::fixed << std::setprecision(15);
Main();
return 0;
} | replace | 465 | 470 | 465 | 470 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
vector<int> v;
while (n--) {
int h;
cin >> h;
v.push_back(abs(x - h));
}
if (v.size() == 1)
cout << v[0] << "\n";
else {
int ans = __gcd(v[0], v[1]);
for (int i = 2; i < v.size(); i++)
ans = __gcd(ans, v[i]);
cout << ans << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> v;
while (n--) {
int h;
cin >> h;
v.push_back(abs(x - h));
}
if (v.size() == 1)
cout << v[0] << "\n";
else {
int ans = __gcd(v[0], v[1]);
for (int i = 2; i < v.size(); i++)
ans = __gcd(ans, v[i]);
cout << ans << "\n";
}
return 0;
}
| insert | 4 | 4 | 4 | 5 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03262 | C++ | Runtime Error | #include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#ifdef ONLINE_JUDGE
const int maxn = 3e5 + 10;
#else
const int maxn = 1e3 + 10;
#endif
using namespace std;
int N, X, arr[maxn];
signed main() {
ios::sync_with_stdio(false);
cin >> N >> X;
for (ri i = 1; i <= N; ++i) {
cin >> arr[i];
}
arr[++N] = X;
sort(arr + 1, arr + 1 + N);
vector<int> v;
for (ri i = 2; i <= N; ++i) {
v.push_back(arr[i] - arr[i - 1]);
}
int gcd = v[0];
for (ri i = 1; i < v.size(); ++i) {
gcd = __gcd(gcd, v[i]);
}
cout << gcd << endl;
return 0;
} | #include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#ifdef ONLINE_JUDGE
const int maxn = 3e5 + 10;
#else
const int maxn = 1e5 + 10;
#endif
using namespace std;
int N, X, arr[maxn];
signed main() {
ios::sync_with_stdio(false);
cin >> N >> X;
for (ri i = 1; i <= N; ++i) {
cin >> arr[i];
}
arr[++N] = X;
sort(arr + 1, arr + 1 + N);
vector<int> v;
for (ri i = 2; i <= N; ++i) {
v.push_back(arr[i] - arr[i - 1]);
}
int gcd = v[0];
for (ri i = 1; i < v.size(); ++i) {
gcd = __gcd(gcd, v[i]);
}
cout << gcd << endl;
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03262 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
ll gcd(ll a, ll b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int main() {
ll N, X;
cin >> N >> X;
ll x[N];
vector<ll> d(N);
rep(i, N) {
cin >> x[i];
d[i] = abs(x[i] - X);
};
ll ans = gcd(d[0], d[1]);
repd(i, 2, N) { ans = gcd(ans, d[i]); }
cout << ans;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
ll gcd(ll a, ll b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int main() {
ll N, X;
cin >> N >> X;
ll x[N];
vector<ll> d(N);
rep(i, N) {
cin >> x[i];
d[i] = abs(x[i] - X);
};
if (d.size() == 1) {
cout << d[0];
return 0;
}
ll ans = gcd(d[0], d[1]);
repd(i, 2, N) { ans = gcd(ans, d[i]); }
cout << ans;
return 0;
} | insert | 29 | 29 | 29 | 35 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int N, X;
int x[100010];
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
cin >> N >> X;
for (int i = 0; i < N; ++i)
cin >> x[i];
sort(begin(x), begin(x) + N);
vector<int> s;
for (int i = 0; i < N; ++i) {
int t = 0;
if (i) {
s.emplace_back(abs(x[i] - x[i - 1]));
}
s.emplace_back(abs(x[i] - X));
}
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
vector<int> ss(s);
for (auto a : s) {
for (auto b : s) {
if (a != b)
ss.emplace_back(gcd(a, b));
}
}
sort(ss.begin(), ss.end());
ss.erase(unique(ss.begin(), ss.end()), ss.end());
int D = 1;
for (auto d : ss) {
int m = X % d;
bool b = true;
for (int j = 0; j < N; ++j) {
if (x[j] % d != m) {
b = false;
break;
}
}
if (b) {
D = max(D, d);
}
}
cout << D << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int N, X;
int x[100010];
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
cin >> N >> X;
for (int i = 0; i < N; ++i)
cin >> x[i];
int D = abs(x[0] - X);
for (int i = 1; i < N; ++i) {
D = gcd(D, abs(x[i] - X));
}
cout << D << endl;
return 0;
} | replace | 16 | 49 | 16 | 19 | TLE | |
p03262 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for (int i = a; i < b; i++)
int gcd(int, int);
int main() {
int n, X;
cin >> n >> X;
vector<int> x(n);
rep(i, 0, n) {
cin >> x[i];
x[i] = abs(X - x[i]);
}
int ans = gcd(x[0], x[1]);
rep(i, 1, n) { ans = gcd(ans, x[i]); }
cout << ans << endl;
return 0;
}
// 最大公約数(ユークリッド互除法)
int gcd(int m, int n) {
ll temp;
while (m % n != 0) {
temp = n;
n = m % n;
m = temp;
}
return n;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for (int i = a; i < b; i++)
int gcd(int, int);
int main() {
int n, X;
cin >> n >> X;
vector<int> x(n);
rep(i, 0, n) {
cin >> x[i];
x[i] = abs(X - x[i]);
}
if (n == 1) {
cout << x[0] << endl;
return 0;
}
int ans = gcd(x[0], x[1]);
rep(i, 1, n) { ans = gcd(ans, x[i]); }
cout << ans << endl;
return 0;
}
// 最大公約数(ユークリッド互除法)
int gcd(int m, int n) {
ll temp;
while (m % n != 0) {
temp = n;
n = m % n;
m = temp;
}
return n;
} | insert | 32 | 32 | 32 | 37 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
long long N, X;
cin >> N >> X;
vector<long long> vec(N);
for (long long i = 0; i < N; i++) {
long long x;
cin >> x;
long long dist = x - X;
if (dist < 0)
dist = -dist;
vec.at(i) = dist;
}
long long ans = GCD(vec.at(0), vec.at(1));
for (int i = 0; i < N; i++) {
ans = GCD(ans, vec.at(i));
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
long long N, X;
cin >> N >> X;
vector<long long> vec(N);
for (long long i = 0; i < N; i++) {
long long x;
cin >> x;
long long dist = x - X;
if (dist < 0)
dist = -dist;
vec.at(i) = dist;
}
long long ans = vec.at(0);
for (int i = 0; i < N; i++) {
ans = GCD(ans, vec.at(i));
}
cout << ans << endl;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int smin(int x, int y) {
if (x == y)
return x;
else if (x > y)
return smin(x - y, y);
else
return smin(y - x, x);
}
int main() {
int n;
long long i, zmin, st, a[maxn] = {0};
cin >> n >> st;
for (i = 1; i <= n; i++) {
cin >> a[i];
a[i] -= st;
if (a[i] < 0)
a[i] = -a[i];
}
zmin = a[1];
for (i = 2; i <= n; i++) {
zmin = smin(zmin, a[i]);
if (zmin == 1) {
cout << '1';
return 0;
}
}
cout << zmin;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int smin(int x, int y) {
if (x == y)
return x;
else if (x > y)
return smin(x - y, y);
else
return smin(y - x, x);
}
int main() {
int n;
long long i, zmin, st, a[maxn] = {0};
cin >> n >> st;
for (i = 1; i <= n; i++) {
cin >> a[i];
a[i] -= st;
if (a[i] < 0)
a[i] = -a[i];
}
zmin = a[1];
for (i = 2; i <= n; i++) {
if (a[i] % zmin == 0)
continue;
zmin = smin(zmin, a[i]);
if (zmin == 1) {
cout << '1';
return 0;
}
}
cout << zmin;
return 0;
} | insert | 25 | 25 | 25 | 27 | TLE | |
p03262 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdint>
#include <iostream>
#include <math.h>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll ans, mx, sum, mn = 1e8;
int main() {
ll n, x;
cin >> n >> x;
ll a[n];
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
ans = a[1] - a[0];
for (ll i = 2; i < n; i++) {
ans = gcd(ans, a[i] - a[0]);
}
if (n == 2) {
for (ll i = abs(x - a[0]); i >= 1; i--) {
if ((a[1] - a[0]) % i == 0) {
cout << i << endl;
return 0;
}
}
} else if (n == 1)
cout << abs(x - a[0]);
else
cout << ans << endl;
}
| #include <algorithm>
#include <cstdint>
#include <iostream>
#include <math.h>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll ans, mx, sum, mn = 1e8;
int main() {
ll n, x;
cin >> n >> x;
ll a[n];
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
ans = a[1] - a[0];
for (ll i = 2; i < n; i++) {
ans = gcd(ans, a[i] - a[0]);
}
if (n == 2) {
cout << gcd(a[0], a[1]);
} else if (n == 1)
cout << abs(x - a[0]);
else
cout << ans << endl;
}
| replace | 31 | 37 | 31 | 32 | TLE | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int m, long long int n) {
if (0 == m || 0 == n)
return 0;
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
}
int main() {
int N;
cin >> N;
long long int X;
cin >> X;
long long int ans, x;
cin >> ans;
ans = abs(ans - X);
for (int i = 1; i < N; i++) {
cin >> x;
x = abs(x - X);
ans = gcd(ans, x);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int m, long long int n) {
if (n == 0)
return m;
else
return gcd(n, m % n);
}
int main() {
int N;
cin >> N;
long long int X;
cin >> X;
long long int ans, x;
cin >> ans;
ans = abs(ans - X);
for (int i = 1; i < N; i++) {
cin >> x;
x = abs(x - X);
ans = gcd(ans, x);
}
cout << ans << endl;
} | replace | 4 | 13 | 4 | 8 | TLE | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int n, a[100020], x, b[100020], sum = 1, lmin = 1000000000, j;
int main() {
cin >> n >> x;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
if (a[i] > x)
b[i] = a[i] - x;
if (a[i] < x)
b[i] = x - a[i];
lmin = min(b[i], lmin);
}
sort(b + n, b + 1 + n);
for (int i = 2; i <= lmin; i++) {
for (j = 1; j <= n; j++) {
if (b[j] % i != 0)
break;
}
if (j > n)
sum = i;
}
cout << sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, a[100020], x, b[100020], sum = 1, lmin = 1000000000, j;
int main() {
cin >> n >> x;
for (int i = 1; i <= n; i++)
cin >> a[i];
if (a[1] == 1000000000) {
cout << 999999999;
return 0;
}
for (int i = 1; i <= n; i++) {
if (a[i] > x)
b[i] = a[i] - x;
if (a[i] < x)
b[i] = x - a[i];
lmin = min(b[i], lmin);
}
sort(b + n, b + 1 + n);
for (int i = 2; i <= lmin; i++) {
for (j = 1; j <= n; j++) {
if (b[j] % i != 0)
break;
}
if (j > n)
sum = i;
}
cout << sum;
return 0;
} | insert | 7 | 7 | 7 | 11 | TLE | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
#define INF 1.0e9
#define MOD 1.0e9 + 7
using namespace std;
typedef long long ll;
int N;
const int MAX_N = 100;
int x[MAX_N + 1];
int gcd(int a, int b) {
int large = max(a, b);
int small = min(a, b);
if (small == 0)
return large;
else
return gcd(small, large % small);
}
int main() {
cin >> N;
for (int i = 0; i < N + 1; i++)
cin >> x[i];
sort(x, x + N + 1);
int diff[N];
for (int i = 0; i < N; i++)
diff[i] = x[i + 1] - x[i];
int ans = diff[0];
for (int i = 1; i < N; i++) {
ans = gcd(ans, diff[i]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define INF 1.0e9
#define MOD 1.0e9 + 7
using namespace std;
typedef long long ll;
int N;
const int MAX_N = 100000;
int x[MAX_N + 1];
int gcd(int a, int b) {
int large = max(a, b);
int small = min(a, b);
if (small == 0)
return large;
else
return gcd(small, large % small);
}
int main() {
cin >> N;
for (int i = 0; i < N + 1; i++)
cin >> x[i];
sort(x, x + N + 1);
int diff[N];
for (int i = 0; i < N; i++)
diff[i] = x[i + 1] - x[i];
int ans = diff[0];
for (int i = 1; i < N; i++) {
ans = gcd(ans, diff[i]);
}
cout << ans << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <iostream>
#include <stdlib.h>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0)
return b;
if (b % a == 0)
return a;
int i, n, m;
if (a < b) {
n = b;
m = a;
i = a;
} else {
n = a;
m = b;
i = b;
}
for (; i > 1; i--) {
if (n % i == 0 && m % i == 0)
break;
}
return i;
}
int main() {
int a, b;
while (1) {
cin >> a >> b;
cout << gcd(a, b) << endl;
}
int n, X, d;
cin >> n >> X;
int *x = new int[n];
cin >> x[0];
d = abs(X - x[0]);
for (int i = 1; i < n; i++) {
cin >> x[i];
d = gcd(d, abs(X - x[i]));
}
cout << d << endl;
return 0;
} | #include <iostream>
#include <stdlib.h>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0)
return b;
if (b % a == 0)
return a;
int i, n, m;
if (a < b) {
n = b;
m = a;
i = a;
} else {
n = a;
m = b;
i = b;
}
for (; i > 1; i--) {
if (n % i == 0 && m % i == 0)
break;
}
return i;
}
int main() {
int n, X, d;
cin >> n >> X;
int *x = new int[n];
cin >> x[0];
d = abs(X - x[0]);
for (int i = 1; i < n; i++) {
cin >> x[i];
d = gcd(d, abs(X - x[i]));
}
cout << d << endl;
return 0;
} | delete | 27 | 32 | 27 | 27 | TLE | |
p03262 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
constexpr int ORD(int n) {
int res = 1;
for (int i = 0; i < n; i++) {
res *= n;
}
res++;
return res;
}
int xs[ORD(6)];
using namespace std;
int gcd_many(int *xs, int n) {
int res = xs[0];
for (int i = 0; i < n; i++) {
res = __gcd(res, xs[i]);
}
return abs(res);
}
int main() {
int N, X;
scanf("%d %d", &N, &X);
for (int i = 0; i < N; i++) {
scanf("%d", xs + i);
xs[i] -= X;
}
int res = gcd_many(xs, N);
printf("%d\n", res);
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
constexpr int ORD(int n) {
int res = 1;
for (int i = 0; i < n; i++) {
res *= 10;
}
res++;
return res;
}
int xs[ORD(6)];
using namespace std;
int gcd_many(int *xs, int n) {
int res = xs[0];
for (int i = 0; i < n; i++) {
res = __gcd(res, xs[i]);
}
return abs(res);
}
int main() {
int N, X;
scanf("%d %d", &N, &X);
for (int i = 0; i < N; i++) {
scanf("%d", xs + i);
xs[i] -= X;
}
int res = gcd_many(xs, N);
printf("%d\n", res);
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() {
int x;
scanf("%d", &x);
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio \
ifstream iofi; \
if (argc > 1) { \
iofi.open(argv[1]); \
std::cin.rdbuf(iofi.rdbuf()); \
}
//--------------------------------------------------------------
// [gcd]
template <class T> T gcd(T a, T b) {
if (a < b)
swap(a, b);
return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) { return a * b / gcd(a, b); }
int main(int argc, char **argv) {
fastio;
myio;
int n;
cin >> n;
ll s;
cin >> s;
vl x(n, 0ll);
vl y(n, 0ll);
cin >> x;
x.pb(s);
sort(rng(x));
adjacent_difference(rng(x), y.begin() - 1);
ll ng = y[0];
rep(i, n) { ng = gcd(ng, y[i]); }
cout << ng;
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() {
int x;
scanf("%d", &x);
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio \
ifstream iofi; \
if (argc > 1) { \
iofi.open(argv[1]); \
std::cin.rdbuf(iofi.rdbuf()); \
}
//--------------------------------------------------------------
// [gcd]
template <class T> T gcd(T a, T b) {
if (a < b)
swap(a, b);
return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) { return a * b / gcd(a, b); }
int main(int argc, char **argv) {
fastio;
myio;
int n;
cin >> n;
ll s;
cin >> s;
vl x(n, 0ll);
vl y(n, 0ll);
cin >> x;
x.pb(s);
sort(rng(x));
rep(i, n) { y[i] = (x[i + 1] - x[i]); }
ll ng = y[0];
rep(i, n) { ng = gcd(ng, y[i]); }
cout << ng;
} | replace | 114 | 115 | 114 | 115 | -6 | free(): invalid pointer
|
p03262 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int solve(int m, int n) {
if (m < n) {
int tmp = m;
m = n;
n = tmp;
}
if (n == 0)
return m;
return solve(n, m - n);
}
int main() {
int N, X;
cin >> N >> X;
int cities[100000];
for (int i = 0; i < N; i++) {
cin >> cities[i];
cities[i] -= X;
cities[i] = abs(cities[i]);
}
int a = cities[0];
for (int i = 1; i < N; i++) {
a = solve(a, cities[i]);
}
cout << a << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int solve(int m, int n) {
if (m < n) {
int tmp = m;
m = n;
n = tmp;
}
if (n == 0)
return m;
return solve(n, m % n);
}
int main() {
int N, X;
cin >> N >> X;
int cities[100000];
for (int i = 0; i < N; i++) {
cin >> cities[i];
cities[i] -= X;
cities[i] = abs(cities[i]);
}
int a = cities[0];
for (int i = 1; i < N; i++) {
a = solve(a, cities[i]);
}
cout << a << endl;
return 0;
}
| replace | 21 | 22 | 21 | 22 | TLE | |
p03262 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
using str = string;
#define rep(a, l, r) for (int a = (l); a < (r); a++)
#define get cin >>
#define put cout <<
int gcd_euclid(int u, int v) {
int r;
while (0 != v) {
r = u % v;
u = v;
v = r; /* swap */
}
return u;
}
void run() {
int n;
get n;
int x;
get x;
int city[x];
rep(i, 0, n) { get city[i]; }
vector<int> distance(n);
rep(i, 0, n) {
if (city[i] < x) {
distance[i] = x - city[i];
} else {
distance[i] = city[i] - x;
}
}
int gcd = *min_element(distance.begin(), distance.end());
rep(i, 0, n) { gcd = gcd_euclid(gcd, distance[i]); }
put gcd;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
run();
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
using str = string;
#define rep(a, l, r) for (int a = (l); a < (r); a++)
#define get cin >>
#define put cout <<
int gcd_euclid(int u, int v) {
int r;
while (0 != v) {
r = u % v;
u = v;
v = r; /* swap */
}
return u;
}
void run() {
int n;
get n;
int x;
get x;
vector<int> city(n);
rep(i, 0, n) { get city[i]; }
vector<int> distance(n);
rep(i, 0, n) {
if (city[i] < x) {
distance[i] = x - city[i];
} else {
distance[i] = city[i] - x;
}
}
int gcd = *min_element(distance.begin(), distance.end());
rep(i, 0, n) { gcd = gcd_euclid(gcd, distance[i]); }
put gcd;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
run();
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
unsigned gcd(unsigned a, unsigned b) {
if (a < b)
return gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
int N, X;
cin >> N >> X;
vector<int> city(N);
for (int i = 0; i < N; ++i) {
cin >> city.at(i);
}
city.push_back(X);
sort(city.begin(), city.end());
vector<int> dcity(N);
for (int i = 0; i < N; ++i) {
dcity.at(i) = city.at(i + 1) - city.at(i);
}
int GCD = gcd(dcity.at(0), dcity.at(1));
for (int i = 0; i < N; ++i) {
if (dcity.at(i))
GCD = gcd(GCD, dcity.at(i));
}
cout << GCD << endl;
} | #include <bits/stdc++.h>
using namespace std;
unsigned gcd(unsigned a, unsigned b) {
if (a < b)
return gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
int N, X;
cin >> N >> X;
vector<int> city(N);
for (int i = 0; i < N; ++i) {
cin >> city.at(i);
}
city.push_back(X);
sort(city.begin(), city.end());
vector<int> dcity(N);
for (int i = 0; i < N; ++i) {
dcity.at(i) = city.at(i + 1) - city.at(i);
}
int GCD;
if (N > 1) {
GCD = gcd(dcity.at(0), dcity.at(1));
} else {
GCD = dcity.at(0);
}
for (int i = 0; i < N; ++i) {
if (dcity.at(i))
GCD = gcd(GCD, dcity.at(i));
}
cout << GCD << endl;
} | replace | 27 | 28 | 27 | 33 | 0 | |
p03262 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
long long n, x;
long long a[10005] = {};
long long b[10005] = {};
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
a[n] = x;
sort(a, a + n + 1);
for (int i = 1; i <= n; i++) {
b[i - 1] = a[i] - a[i - 1];
}
long long r;
long long ans = 1000000005;
for (int i = 1; i <= n; i++) {
r = b[i] % b[i - 1];
while (r != 0) {
b[i] = b[i - 1];
b[i - 1] = r;
r = b[i] % b[i - 1];
}
if (ans > b[i - 1])
ans = b[i - 1];
}
cout << ans;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
long long n, x;
long long a[100050] = {};
long long b[100050] = {};
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
a[n] = x;
sort(a, a + n + 1);
for (int i = 1; i <= n; i++) {
b[i - 1] = a[i] - a[i - 1];
}
long long r;
long long ans = 1000000005;
for (int i = 1; i <= n; i++) {
r = b[i] % b[i - 1];
while (r != 0) {
b[i] = b[i - 1];
b[i - 1] = r;
r = b[i] % b[i - 1];
}
if (ans > b[i - 1])
ans = b[i - 1];
}
cout << ans;
} | replace | 17 | 19 | 17 | 19 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int gcd(int m, int n) {
// 引数に0がある場合は0を返す
if ((0 == m) || (0 == n))
return 0;
// ユークリッドの方法
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
}
int main() {
int N, X;
cin >> N >> X;
vector<int> x(N);
rep(i, N) cin >> x[i];
rep(i, N) x[i] = abs(X - x[i]);
int ans = x[0];
rep(i, N) { ans = gcd(ans, x[i]); }
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int gcd(int m, int n) {
// 引数に0がある場合は0を返す
if ((0 == m) || (0 == n))
return 0;
// ユークリッドの方法
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
}
int main() {
int N, X;
cin >> N >> X;
vector<int> x(N);
rep(i, N) cin >> x[i];
rep(i, N) x[i] = abs(X - x[i]);
int ans = x[0];
rep(i, N) {
if (x[i] % ans == 0)
continue;
ans = gcd(ans, x[i]);
}
cout << ans << endl;
return 0;
}
| replace | 29 | 30 | 29 | 34 | TLE | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int gcd(int P, int Q);
int main() {
int N;
cin >> N;
N++;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
sort(A.begin(), A.end());
int D = gcd((A.at(1) - A.at(0)), (A.at(2) - A.at(1)));
int C;
for (int i = 3; i < N; i++) {
C = gcd((A.at(i - 1) - A.at(i - 2)), (A.at(i) - A.at(i - 1)));
if (C < D) {
D = C;
}
}
cout << D << endl;
}
int gcd(int P, int Q) {
int r = P % Q;
if (r == 0) {
return Q;
}
int rr = Q % r;
if (rr == 0) {
return r;
}
while ((r != 0) || (rr != 0)) {
r = r % rr;
if (r == 0) {
return rr;
}
rr = rr % r;
if (rr == 0) {
return r;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
int gcd(int P, int Q);
int main() {
int N;
cin >> N;
N++;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
sort(A.begin(), A.end());
if (N == 2) {
cout << A.at(1) - A.at(0) << endl;
exit(0);
}
int D = gcd((A.at(1) - A.at(0)), (A.at(2) - A.at(1)));
int C;
for (int i = 3; i < N; i++) {
C = gcd((A.at(i - 1) - A.at(i - 2)), (A.at(i) - A.at(i - 1)));
if (C < D) {
D = C;
}
}
cout << D << endl;
}
int gcd(int P, int Q) {
int r = P % Q;
if (r == 0) {
return Q;
}
int rr = Q % r;
if (rr == 0) {
return r;
}
while ((r != 0) || (rr != 0)) {
r = r % rr;
if (r == 0) {
return rr;
}
rr = rr % r;
if (rr == 0) {
return r;
}
}
} | insert | 16 | 16 | 16 | 21 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all_map(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;
ll Gcd(ll a, ll b) {
if (a < b)
swap(a, b);
if (a % b == 0)
return (b);
else
return (Gcd(b, a % b));
}
int main() {
ll n, x;
cin >> n >> x;
ll dist[x];
rep(i, n) {
ll x_i;
cin >> x_i;
dist[i] = abs(x - x_i);
}
ll ans = dist[0];
for (ll i = 1; i < n; ++i) {
ans = Gcd(ans, dist[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all_map(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;
ll Gcd(ll a, ll b) {
if (a < b)
swap(a, b);
if (a % b == 0)
return (b);
else
return (Gcd(b, a % b));
}
int main() {
ll n, x;
cin >> n >> x;
ll dist[n];
rep(i, n) {
ll x_i;
cin >> x_i;
dist[i] = abs(x - x_i);
}
ll ans = dist[0];
for (ll i = 1; i < n; ++i) {
ans = Gcd(ans, dist[i]);
}
cout << ans << endl;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p03262 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
unsigned GCD(unsigned u, unsigned v) {
while (v != 0) {
unsigned r = u % v;
u = v;
v = r;
}
return u;
}
int main() {
int N, X, maxD = 0;
std::cin >> N >> X;
int a[N];
for (int i = 0; i < N; i++)
std::cin >> a[i];
for (int i = 0; i < N; i++)
maxD = std::max(maxD, a[i]);
int minD = std::abs(X - maxD);
for (int i = 0; i < N - 1; i++)
for (int j = i + 1; j < N; j++)
minD = GCD(GCD(std::abs(X - a[i]), std::abs(X - a[j])), minD);
std::cout << minD << std::endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
unsigned GCD(unsigned u, unsigned v) {
while (v != 0) {
unsigned r = u % v;
u = v;
v = r;
}
return u;
}
int main() {
int N, X, maxD = 0;
std::cin >> N >> X;
int a[N];
for (int i = 0; i < N; i++)
std::cin >> a[i];
for (int i = 0; i < N; i++)
maxD = std::max(maxD, a[i]);
int minD = std::abs(X - maxD);
for (int i = 0; i < N; i++)
minD = std::min(minD, std::abs(X - a[i]));
for (int i = 0; i < N; i++)
minD = GCD(std::abs(X - a[i]), minD);
std::cout << minD << std::endl;
return 0;
} | replace | 26 | 29 | 26 | 31 | TLE | |
p03262 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int yakusuu(int a, int b) {
if (b % a == 0)
return a;
else
return yakusuu(b % a, a);
}
int main() {
int N, X, x[100000], baisuu, k, b = 0, a = 0;
cin >> N >> X;
cin >> x[0];
x[0] -= X;
if (x[0] < 0)
x[0] *= -1;
// baisuu=x[0];
for (int i = 1; i < N; i++) {
cin >> x[i];
x[i] -= X;
if (x[i] < 0)
x[i] *= -1;
// if(baisuu>x[i])baisuu=x[i];
}
baisuu = yakusuu(x[0], x[1]);
for (int i = 2; i < N, baisuu != 1; i++) {
b = yakusuu(x[i - 1], x[i]);
baisuu = yakusuu(b, baisuu);
}
/*for(int i=0;i<N;i++){
x[i]%=baisuu;
if(x[i]==0)a++;
if(a==N){
cout<<baisuu<<endl;
return 0;
}
}
for(int i=0;i<N,baisuu!=1;i++){
if(x[i]==0);
else if(yakusuu(baisuu,x[i])==1){
b=1;
cout<<b<<endl;
return 0;
}
else {
baisuu=yakusuu(baisuu,x[i]);
for(int i=0;i<N;i++){
x[i]%=baisuu;
}
}
}*/
cout << baisuu << endl;
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
int yakusuu(int a, int b) {
if (b % a == 0)
return a;
else
return yakusuu(b % a, a);
}
int main() {
int N, X, x[100000], baisuu, k, b = 0, a = 0;
cin >> N >> X;
cin >> x[0];
x[0] -= X;
if (x[0] < 0)
x[0] *= -1;
// baisuu=x[0];
for (int i = 1; i < N; i++) {
cin >> x[i];
x[i] -= X;
if (x[i] < 0)
x[i] *= -1;
// if(baisuu>x[i])baisuu=x[i];
}
baisuu = yakusuu(x[0], x[1]);
for (int i = 2; i < N && baisuu != 1; i++) {
b = yakusuu(x[i - 1], x[i]);
baisuu = yakusuu(b, baisuu);
}
/*for(int i=0;i<N;i++){
x[i]%=baisuu;
if(x[i]==0)a++;
if(a==N){
cout<<baisuu<<endl;
return 0;
}
}
for(int i=0;i<N,baisuu!=1;i++){
if(x[i]==0);
else if(yakusuu(baisuu,x[i])==1){
b=1;
cout<<b<<endl;
return 0;
}
else {
baisuu=yakusuu(baisuu,x[i]);
for(int i=0;i<N;i++){
x[i]%=baisuu;
}
}
}*/
cout << baisuu << endl;
return 0;
}
| replace | 25 | 26 | 25 | 26 | -8 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define N 10000
int n, X;
int x[N];
long long gcd(int u, int v) {
int r;
while (0 != v) {
r = u % v;
u = v;
v = r;
}
return u;
}
int main() {
int n;
cin >> n >> X;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
long long ans = abs(x[0] - X);
if (n > 1) {
for (int i = 1; i < n; i++) {
ans = gcd(ans, abs(x[i] - X));
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define N 100000
int n, X;
int x[N];
long long gcd(int u, int v) {
int r;
while (0 != v) {
r = u % v;
u = v;
v = r;
}
return u;
}
int main() {
int n;
cin >> n >> X;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
long long ans = abs(x[0] - X);
if (n > 1) {
for (int i = 1; i < n; i++) {
ans = gcd(ans, abs(x[i] - X));
}
}
cout << ans << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03262 | Python | Runtime Error | import math
N, X = map(int, input().split())
X_lst = list(map(int, input().split()))
if len(X_lst) == 1:
print(abs(X_lst[0] - X))
exit()
u = 0
if X_lst[0] == X:
u = float("inf")
for i, x in enumerate(X_lst[1:], start=1):
if x == X:
u = float("inf")
if X_lst[i - 1] < X < x:
u = [X - u, x - X]
if i == 1:
g = X_lst[1] - X_lst[0]
else:
g = math.gcd(g, x - X_lst[i - 1])
if u == 0:
u = [X - X_lst[-1]]
elif u != float("inf"):
g = max(math.gcd(g, u[0]), math.gcd(g, u[1]))
print(g)
| import math
N, X = map(int, input().split())
X_lst = list(map(int, input().split()))
if len(X_lst) == 1:
print(abs(X_lst[0] - X))
exit()
u = 0
if X_lst[0] == X:
u = float("inf")
for i, x in enumerate(X_lst[1:], start=1):
if x == X:
u = float("inf")
if X_lst[i - 1] < X < x:
u = [X - X_lst[-1], x - X]
if i == 1:
g = X_lst[1] - X_lst[0]
else:
g = math.gcd(g, x - X_lst[i - 1])
if u == 0:
u = [X - X_lst[-1]]
elif u != float("inf"):
g = max(math.gcd(g, u[0]), math.gcd(g, u[1]))
print(g)
| replace | 18 | 19 | 18 | 19 | 0 | |
p03262 | Python | Runtime Error | from math import gcd
from functools import reduce
def gcd_list(numbers):
return reduce(gcd, numbers)
n, x = map(int, input().split())
x_arr = [0] * n
x_arr = list(map(int, input().split()))
for i in range(len(x_arr)):
x_arr[i] = abs(x_arr[i] - x)
print(gcd_list(x_arr))
| from fractions import gcd
from functools import reduce
def gcd_list(numbers):
return reduce(gcd, numbers)
n, x = map(int, input().split())
x_arr = [0] * n
x_arr = list(map(int, input().split()))
for i in range(len(x_arr)):
x_arr[i] = abs(x_arr[i] - x)
print(gcd_list(x_arr))
| replace | 0 | 1 | 0 | 1 | 0 | |
p03262 | Python | Runtime Error | from fractions import gcd
N, X = map(int, input().split())
X_list = list(map(int, input().split()))
dX = [abs(X - x) for x in X_list]
if len(dX) == 1:
print(dX[0])
exit(0)
D = [abs(X_list[i] - X_list[i + 1]) for i in range(0, N - 1)]
res = gcd(D[0], D[1])
for x in D[2:]:
res = gcd(res, x)
ans = 0
for d in dX:
ans = max(gcd(res, d), ans)
print(ans)
| from fractions import gcd
N, X = map(int, input().split())
X_list = list(map(int, input().split()))
dX = [abs(X - x) for x in X_list]
if len(dX) == 1:
print(dX[0])
exit(0)
D = [abs(X_list[i] - X_list[i + 1]) for i in range(0, N - 1)]
res = D[0]
for x in D[1:]:
res = gcd(res, x)
ans = 0
for d in dX:
ans = max(gcd(res, d), ans)
print(ans)
| replace | 11 | 13 | 11 | 13 | ImportError: cannot import name 'gcd' from 'fractions' (/usr/lib/python3.10/fractions.py) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03262/Python/s082976387.py", line 1, in <module>
from fractions import gcd
ImportError: cannot import name 'gcd' from 'fractions' (/usr/lib/python3.10/fractions.py)
|
p03262 | Python | Runtime Error | n, s = map(int, input().split())
xxx = [abs(s - y) for y in map(int, input().split())]
d = 0
while True:
d = min(xxx)
xxx = [x % d for x in xxx]
if all(x == 0 for x in xxx):
break
print(d)
| n, s = map(int, input().split())
xxx = [abs(s - y) for y in map(int, input().split())]
d = 0
while True:
xxx = [x for x in xxx if x > 0]
d = min(xxx)
xxx = [x % d for x in xxx]
if all(x == 0 for x in xxx):
break
print(d)
| insert | 4 | 4 | 4 | 5 | 0 | |
p03262 | Python | Runtime Error | def gcd(a, b):
if a > b:
a, b = b, a
while b > 0:
a, b = b, a % b
return a
def allgcd(d):
if len(d) == 1:
return d
ret_gcd = d[0]
for i in d:
ret_gcd = gcd(ret_gcd, i)
return ret_gcd
def maxNumVisitCity(N, X, x):
if len(x) == 1:
return abs(x[0] - X)
d = []
for i in x:
d.append(abs(i - X))
return allgcd(d)
def main():
N, X = map(int, input().split())
x = map(int, input().split())
print(maxNumVisitCity(N, X, x))
if __name__ == "__main__":
main()
| def gcd(a, b):
if a > b:
a, b = b, a
while b > 0:
a, b = b, a % b
return a
def allgcd(d):
if len(d) == 1:
return d
ret_gcd = d[0]
for i in d:
ret_gcd = gcd(ret_gcd, i)
return ret_gcd
def maxNumVisitCity(N, X, x):
if len(x) == 1:
return abs(x[0] - X)
d = []
for i in x:
d.append(abs(i - X))
return allgcd(d)
def main():
N, X = map(int, input().split())
x = list(map(int, input().split()))
print(maxNumVisitCity(N, X, x))
if __name__ == "__main__":
main()
| replace | 29 | 30 | 29 | 30 | TypeError: object of type 'map' has no len() | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03262/Python/s914485510.py", line 35, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03262/Python/s914485510.py", line 31, in main
print(maxNumVisitCity(N, X, x))
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03262/Python/s914485510.py", line 19, in maxNumVisitCity
if len(x) == 1:
TypeError: object of type 'map' has no len()
|
p03262 | Python | Time Limit Exceeded | n, x = map(int, input().split())
li = list(map(int, input().split()))
t = []
for i in li:
t.append(abs(i - x))
for j in range(min(t)):
if all(k % (min(t) - j) == 0 for k in t):
print(min(t) - j)
exit()
| n, x = map(int, input().split())
li = list(map(int, input().split()))
t = []
for i in li:
t.append(abs(i - x))
divisors = []
for i in range(1, int(min(t) ** 0.5) + 1):
if min(t) % i == 0:
divisors.append(i)
if i != min(t) // i:
divisors.append(min(t) // i)
divisors.sort()
divisors = divisors[::-1]
for j in divisors:
if all(k % j == 0 for k in t):
print(j)
exit()
| replace | 5 | 8 | 5 | 16 | TLE | |
p03262 | Python | Runtime Error | from functools import reduce
from math import gcd
X = int(input().split()[1])
x = [abs(int(x) - X) for x in input().split()]
print(reduce(gcd, x))
| from functools import reduce
from fractions import gcd
X = int(input().split()[1])
x = [abs(int(x) - X) for x in input().split()]
print(reduce(gcd, x))
| replace | 1 | 2 | 1 | 2 | 0 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, a[100007];
int gcd(int x, int y) {
if (x == 0)
return y;
else
return gcd(y, x % y);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> a[0];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a, a + n + 1);
int g = 0;
for (int i = 1; i <= n; i++) {
g = gcd(g, a[i] - a[i - 1]);
}
cout << g << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, a[100007];
int gcd(int x, int y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> a[0];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a, a + n + 1);
int g = 0;
for (int i = 1; i <= n; i++) {
g = gcd(g, a[i] - a[i - 1]);
}
cout << g << endl;
return 0;
} | replace | 4 | 6 | 4 | 6 | -8 | |
p03262 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int(i) = 0; i < (n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, ans, x[n + 1];
cin >> n;
REP(i, n + 1) cin >> x[i];
sort(x, x + n + 1);
ans = x[1] - x[0];
REP(i, n) ans = gcd(ans, x[i + 1] - x[i]);
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int(i) = 0; i < (n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, ans, x[100001];
cin >> n;
REP(i, n + 1) cin >> x[i];
sort(x, x + n + 1);
ans = x[1] - x[0];
REP(i, n) ans = gcd(ans, x[i + 1] - x[i]);
cout << ans;
} | replace | 7 | 8 | 7 | 8 | -11 |
Subsets and Splits