buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 0 && c == 0) {
cout << "close" << endl;
}
if (a == 0 && b == 1 && c == 0) {
cout << "close" << endl;
}
if (a == 1 && b == 1 && c == 0) {
cout << "open" << endl;
}
if (a == 0 && b == 0 && c == 1) {
cout << "open" << endl;
}
if (a == 0 && b == 0 && c == 0) {
cout << "close" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 0 && c == 0) {
cout << "Close" << endl;
}
if (a == 0 && b == 1 && c == 0) {
cout << "Close" << endl;
}
if (a == 1 && b == 1 && c == 0) {
cout << "Open" << endl;
}
if (a == 0 && b == 0 && c == 1) {
cout << "Open" << endl;
}
if (a == 0 && b == 0 && c == 0) {
cout << "Close" << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 150
| 10
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d%d%d", &b1, &b2, &b3);
if (b3 == 1) {
printf("Open\n");
} else if (b1 == 0 && b2 == 0) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d%d%d", &b1, &b2, &b3);
if (b3 == 1) {
printf("Open\n");
} else if (b1 == 1 && b2 == 1) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 83
| 4
|
//============================================================================
// Name : AOJ.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 0 && c == 0)
cout << "Close" << endl;
if (a == 0 && b == 1 && c == 0)
cout << "Close" << endl;
if (a == 1 && b == 1 && c == 0)
cout << "Close" << endl;
if (a == 0 && b == 0 && c == 1)
cout << "Open" << endl;
if (a == 0 && b == 0 && c == 0)
cout << "Open" << endl;
return 0;
}
|
//============================================================================
// Name : AOJ.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 0 && c == 0)
cout << "Close" << endl;
if (a == 0 && b == 1 && c == 0)
cout << "Close" << endl;
if (a == 1 && b == 1 && c == 0)
cout << "Open" << endl;
if (a == 0 && b == 0 && c == 1)
cout << "Open" << endl;
if (a == 0 && b == 0 && c == 0)
cout << "Close" << endl;
return 0;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 153
| 4
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 1) {
cout << "Open" << endl;
}
if (c == 1) {
cout << "Open" << endl;
} else {
cout << "Close" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 1) {
cout << "Open" << endl;
} else if (c == 1) {
cout << "Open" << endl;
} else {
cout << "Close" << endl;
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 77
| 1
|
#include <iostream>
using namespace std;
int main(void) {
int b[3];
for (int i = 0; i < 3; i++) {
cin >> b[i];
}
if ((b[0] == 1 && b[1] == 1) && b[2] == 0) {
cout << "open" << endl;
} else if ((b[0] == 0 && b[1] == 0) && b[2] == 1) {
cout << "open" << endl;
} else {
cout << "close" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void) {
int b[3];
for (int i = 0; i < 3; i++) {
cin >> b[i];
}
if ((b[0] == 1 && b[1] == 1) && b[2] == 0) {
cout << "Open" << endl;
} else if ((b[0] == 0 && b[1] == 0) && b[2] == 1) {
cout << "Open" << endl;
} else {
cout << "Close" << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 127
| 6
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 0 && b2 == 0 && b3 == 1)
printf("Open\n");
else
printf("Close\n");
return 0;
}
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 1 && b2 == 1 || b3 == 1)
printf("Open\n");
else
printf("Close\n");
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 31, 16, 12, 13], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 12, 13], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106]]
| 1
| 66
| 6
|
#include <stdio.h>
int main(void) {
int a, b = 0, c, i, j;
scanf("%d %d %d", &a, &b, &c);
if (a == 1) {
if (b == 0) {
printf("Close\n");
}
if (b == 1) {
printf("Open\n");
}
} else {
if (b == 0) {
if (c == 0) {
printf("close\n");
}
if (c == 1) {
printf("Open\n");
}
}
if (b == 1) {
printf("Close\n");
}
}
}
|
#include <stdio.h>
int main(void) {
int a, b = 0, c, i, j;
scanf("%d %d %d", &a, &b, &c);
if (a == 1) {
if (b == 0) {
printf("Close\n");
}
if (b == 1) {
printf("Open\n");
}
} else {
if (b == 0) {
if (c == 0) {
printf("Close\n");
}
if (c == 1) {
printf("Open\n");
}
}
if (b == 1) {
printf("Close\n");
}
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 137
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 1 && c == 0 && a == 0 && b == 0 && c == 1)
cout << "Open" << endl;
else
cout << "Close" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 1 && c == 0 || a == 0 && b == 0 && c == 1)
cout << "Open" << endl;
else
cout << "Close" << endl;
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 31, 16, 17, 98], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106]]
| 1
| 73
| 2
|
#include <bits/stdc++.h>
using namespace std;
// pp basics
#define in ,
#define esc_paren(...) __VA_ARGS__
#define pp_empty(...)
#define pp_cat_i(x, y) x##y
#define pp_cat(x, y) pp_cat_i(x, y)
#define pp_inc0 1
#define pp_inc1 2
#define pp_inc2 3
#define pp_inc3 4
#define pp_inc4 5
#define pp_inc5 6
#define pp_inc6 7
#define pp_inc7 8
#define pp_inc8 9
#define pp_inc(i) pp_cat(pp_inc, i)
// pp args counter
#define pp_arg10(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, ...) _9
#define pp_has_comma(...) pp_arg10(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 0)
#define pp_trigger_paren(...) ,
#define pp_is_empty(...) \
pp_is_empty1(pp_has_comma(__VA_ARGS__), \
pp_has_comma(pp_trigger_paren __VA_ARGS__), \
pp_has_comma(__VA_ARGS__()), \
pp_has_comma(pp_trigger_paren __VA_ARGS__()))
#define pp_paste5(_0, _1, _2, _3, _4) _0##_1##_2##_3##_4
#define pp_is_empty1(_0, _1, _2, _3) \
pp_has_comma(pp_paste5(pp_is_empty_case_, _0, _1, _2, _3))
#define pp_is_empty_case_0001 ,
#define pp_is_one(...) pp_is_one_(__VA_ARGS__, pp_one_seq)
#define pp_is_one_(...) pp_is_one_n(__VA_ARGS__)
#define pp_is_one_n(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
#define pp_one_seq 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0
#define pp_narg(...) pp_narg_(__VA_ARGS__, pp_narg_seq)
#define pp_narg_(...) pp_narg_n(__VA_ARGS__)
#define pp_narg_n(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, \
_15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, \
_27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, \
_39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, \
_63, n, ...) \
n
#define pp_narg_seq \
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, \
44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, \
26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, \
8, 7, 6, 5, 4, 3, 2, 1, 0
// pp if
#define pp_if_0(x, y) y
#define pp_if_1(x, y) x
#define pp_if(cond, x, y) pp_cat(pp_if_, cond)(x, y)
// pp foreach
#define pp_foreach_i9(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i8(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i7(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i6(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i5(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i4(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i3(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i2(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i1(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i0(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i(i, f, ...) \
pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach(f, ...) pp_foreach_i(0, f, __VA_ARGS__)
// alternative rep macro
#define rep(...) rep1(rep2, (__VA_ARGS__))
#define rep1(X, A) X A
#define rep2(i, ...) \
pp_if(pp_is_one(__VA_ARGS__), rep_len1(i, __VA_ARGS__), rep3(i, __VA_ARGS__))
#define rep_len1(i, end, ...) for (int i = 0; i < end; i++)
#define rep3(i, iter, ...) rep4(rep5, (iter, i, esc_paren __VA_ARGS__))
#define rep4(X, A) X A
#define rep5(iter, ...) iter(__VA_ARGS__)
// iterators
#define up up_iter,
#define up_iter3(i, start, end) for (int i = start; i < end; i++)
#define up_iter4(i, start, end, up) for (int i = start; i < end; i += up)
#define up_iter(...) pp_cat(up_iter, pp_narg(__VA_ARGS__))(__VA_ARGS__)
#define down down_iter,
#define down_iter2(i, end) for (int i = end - 1; i >= 0; i--)
#define down_iter3(i, start, end) for (int i = end - 1; i >= start; i--)
#define down_iter4(i, start, end, down) \
for (int i = end - 1; i >= start; i -= down)
#define down_iter(...) pp_cat(down_iter, pp_narg(__VA_ARGS__))(__VA_ARGS__)
#define viter viter_iter,
#define viter_iter(i, v) \
auto tmpitr = v.begin(); \
for (auto i = *tmpitr; tmpitr != v.end(); tmpitr++)
// debug macros
#define debug_var_elem(v) << #v << "=" << v << " "
#ifdef DEBUG
#define debug_echo(e) cout << "L" << __LINE__ << ": " << e << endl
#define debug_var(...) \
cout << "L" << __LINE__ << ": " pp_foreach(debug_var_elem, __VA_ARGS__) \
<< endl
#define debug_ary(ary, n) \
cout << "L" << __LINE__ << " [ "; \
for (int i = 0; i < n; i++) \
cout << ary[i] << " "; \
cout << "]" << endl;
#else
#define debug_echo(e)
#define debug_var(...)
#define debug_ary(ary, n)
#endif
// short names
typedef long long ll;
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
ll gcd(ll a, ll b) {
while (b) {
ll tmp = a % b;
a = b;
b = tmp;
}
return a;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define all(x) x.begin(), x.end()
#define split_str(str, sp_word) \
istringstream stream(str); \
string res; \
for (int cnt = 0; getline(stream, res, sp_word); cnt++)
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define vec_cpy(to, from) copy(all(to), back_inserter(from))
#define ary_cpy(to, from) memcpy(to, from, sizeof(from))
#define MOD 1000000007
// pp unionfind
#define pp_gen_field(list) pp_gen_field1 list
#define pp_gen_field1(name, val) decltype(val) name;
#define pp_gen_init(list) pp_gen_init1 list
#define pp_gen_init1(name, val) , val
#define pp_gen_find_set_wrap(ufnodename) ufnodename pp_gen_find_set
#define pp_gen_find_set(list) pp_gen_find_set1 list
#define pp_gen_find_set1(name, val) \
find_set_##name(int x, decltype(val) v) { \
if (nodes[x].parent == x) { \
nodes[x].name = v; \
return nodes[x]; \
} else { \
return nodes[x] = find_set_##name(nodes[x].parent, v); \
} \
}
#define pp_gen_unite_set(list) pp_gen_unite_set1 list
#define pp_gen_unite_set1(name, val) \
if (nodes[x].name == val) { \
find_set_##name(x, find(y).name); \
} \
if (nodes[y].name == val) { \
find_set_##name(y, find(x).name); \
}
#define def_unionfind(ufname, ufnodename, ...) \
struct ufnodename { \
int parent; \
pp_foreach(pp_gen_field, __VA_ARGS__) \
}; \
struct ufname { \
vector<ufnodename> nodes; \
vector<int> rank; \
ufname(int n) : nodes(n + 1), rank(n + 1) { \
rep(i in n) { \
nodes[i] = ufnodename{i pp_foreach(pp_gen_init, __VA_ARGS__)}; \
rank[i] = 0; \
} \
} \
ufnodename find(int x) { \
if (nodes[x].parent == x) { \
return nodes[x]; \
} else { \
return nodes[x] = find(nodes[x].parent); \
} \
} \
pp_foreach(pp_gen_find_set_wrap(ufnodename), \
__VA_ARGS__) void unite(int x, int y) { \
x = find(x).parent; \
y = find(y).parent; \
if (x == y) \
return; \
if (rank[x] < rank[y]) { \
pp_foreach(pp_gen_unite_set, __VA_ARGS__); \
nodes[x].parent = y; \
} else { \
pp_foreach(pp_gen_unite_set, __VA_ARGS__); \
nodes[y].parent = x; \
if (rank[x] == rank[y]) \
rank[x]++; \
} \
} \
bool same(int x, int y) { return find(x).parent == find(y).parent; } \
}
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 0 && c == 0)
cout << "Open" << endl;
else if (a == 0 && b == 1 && c == 0)
cout << "Close" << endl;
else if (a == 1 && b == 1 && c == 0)
cout << "Open" << endl;
else if (a == 0 && b == 0 && c == 1)
cout << "Open" << endl;
else if (a == 0 && b == 0 && c == 0)
cout << "Close" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
// pp basics
#define in ,
#define esc_paren(...) __VA_ARGS__
#define pp_empty(...)
#define pp_cat_i(x, y) x##y
#define pp_cat(x, y) pp_cat_i(x, y)
#define pp_inc0 1
#define pp_inc1 2
#define pp_inc2 3
#define pp_inc3 4
#define pp_inc4 5
#define pp_inc5 6
#define pp_inc6 7
#define pp_inc7 8
#define pp_inc8 9
#define pp_inc(i) pp_cat(pp_inc, i)
// pp args counter
#define pp_arg10(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, ...) _9
#define pp_has_comma(...) pp_arg10(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 0)
#define pp_trigger_paren(...) ,
#define pp_is_empty(...) \
pp_is_empty1(pp_has_comma(__VA_ARGS__), \
pp_has_comma(pp_trigger_paren __VA_ARGS__), \
pp_has_comma(__VA_ARGS__()), \
pp_has_comma(pp_trigger_paren __VA_ARGS__()))
#define pp_paste5(_0, _1, _2, _3, _4) _0##_1##_2##_3##_4
#define pp_is_empty1(_0, _1, _2, _3) \
pp_has_comma(pp_paste5(pp_is_empty_case_, _0, _1, _2, _3))
#define pp_is_empty_case_0001 ,
#define pp_is_one(...) pp_is_one_(__VA_ARGS__, pp_one_seq)
#define pp_is_one_(...) pp_is_one_n(__VA_ARGS__)
#define pp_is_one_n(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
#define pp_one_seq 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0
#define pp_narg(...) pp_narg_(__VA_ARGS__, pp_narg_seq)
#define pp_narg_(...) pp_narg_n(__VA_ARGS__)
#define pp_narg_n(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, \
_15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, \
_27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, \
_39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, \
_63, n, ...) \
n
#define pp_narg_seq \
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, \
44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, \
26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, \
8, 7, 6, 5, 4, 3, 2, 1, 0
// pp if
#define pp_if_0(x, y) y
#define pp_if_1(x, y) x
#define pp_if(cond, x, y) pp_cat(pp_if_, cond)(x, y)
// pp foreach
#define pp_foreach_i9(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i8(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i7(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i6(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i5(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i4(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i3(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i2(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i1(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i0(i, f, x, ...) \
f(x) pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach_i(i, f, ...) \
pp_if(pp_is_empty(__VA_ARGS__), pp_empty, \
pp_cat(pp_foreach_i, i))(pp_inc(i), f, __VA_ARGS__)
#define pp_foreach(f, ...) pp_foreach_i(0, f, __VA_ARGS__)
// alternative rep macro
#define rep(...) rep1(rep2, (__VA_ARGS__))
#define rep1(X, A) X A
#define rep2(i, ...) \
pp_if(pp_is_one(__VA_ARGS__), rep_len1(i, __VA_ARGS__), rep3(i, __VA_ARGS__))
#define rep_len1(i, end, ...) for (int i = 0; i < end; i++)
#define rep3(i, iter, ...) rep4(rep5, (iter, i, esc_paren __VA_ARGS__))
#define rep4(X, A) X A
#define rep5(iter, ...) iter(__VA_ARGS__)
// iterators
#define up up_iter,
#define up_iter3(i, start, end) for (int i = start; i < end; i++)
#define up_iter4(i, start, end, up) for (int i = start; i < end; i += up)
#define up_iter(...) pp_cat(up_iter, pp_narg(__VA_ARGS__))(__VA_ARGS__)
#define down down_iter,
#define down_iter2(i, end) for (int i = end - 1; i >= 0; i--)
#define down_iter3(i, start, end) for (int i = end - 1; i >= start; i--)
#define down_iter4(i, start, end, down) \
for (int i = end - 1; i >= start; i -= down)
#define down_iter(...) pp_cat(down_iter, pp_narg(__VA_ARGS__))(__VA_ARGS__)
#define viter viter_iter,
#define viter_iter(i, v) \
auto tmpitr = v.begin(); \
for (auto i = *tmpitr; tmpitr != v.end(); tmpitr++)
// debug macros
#define debug_var_elem(v) << #v << "=" << v << " "
#ifdef DEBUG
#define debug_echo(e) cout << "L" << __LINE__ << ": " << e << endl
#define debug_var(...) \
cout << "L" << __LINE__ << ": " pp_foreach(debug_var_elem, __VA_ARGS__) \
<< endl
#define debug_ary(ary, n) \
cout << "L" << __LINE__ << " [ "; \
for (int i = 0; i < n; i++) \
cout << ary[i] << " "; \
cout << "]" << endl;
#else
#define debug_echo(e)
#define debug_var(...)
#define debug_ary(ary, n)
#endif
// short names
typedef long long ll;
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
ll gcd(ll a, ll b) {
while (b) {
ll tmp = a % b;
a = b;
b = tmp;
}
return a;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define all(x) x.begin(), x.end()
#define split_str(str, sp_word) \
istringstream stream(str); \
string res; \
for (int cnt = 0; getline(stream, res, sp_word); cnt++)
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define vec_cpy(to, from) copy(all(to), back_inserter(from))
#define ary_cpy(to, from) memcpy(to, from, sizeof(from))
#define MOD 1000000007
// pp unionfind
#define pp_gen_field(list) pp_gen_field1 list
#define pp_gen_field1(name, val) decltype(val) name;
#define pp_gen_init(list) pp_gen_init1 list
#define pp_gen_init1(name, val) , val
#define pp_gen_find_set_wrap(ufnodename) ufnodename pp_gen_find_set
#define pp_gen_find_set(list) pp_gen_find_set1 list
#define pp_gen_find_set1(name, val) \
find_set_##name(int x, decltype(val) v) { \
if (nodes[x].parent == x) { \
nodes[x].name = v; \
return nodes[x]; \
} else { \
return nodes[x] = find_set_##name(nodes[x].parent, v); \
} \
}
#define pp_gen_unite_set(list) pp_gen_unite_set1 list
#define pp_gen_unite_set1(name, val) \
if (nodes[x].name == val) { \
find_set_##name(x, find(y).name); \
} \
if (nodes[y].name == val) { \
find_set_##name(y, find(x).name); \
}
#define def_unionfind(ufname, ufnodename, ...) \
struct ufnodename { \
int parent; \
pp_foreach(pp_gen_field, __VA_ARGS__) \
}; \
struct ufname { \
vector<ufnodename> nodes; \
vector<int> rank; \
ufname(int n) : nodes(n + 1), rank(n + 1) { \
rep(i in n) { \
nodes[i] = ufnodename{i pp_foreach(pp_gen_init, __VA_ARGS__)}; \
rank[i] = 0; \
} \
} \
ufnodename find(int x) { \
if (nodes[x].parent == x) { \
return nodes[x]; \
} else { \
return nodes[x] = find(nodes[x].parent); \
} \
} \
pp_foreach(pp_gen_find_set_wrap(ufnodename), \
__VA_ARGS__) void unite(int x, int y) { \
x = find(x).parent; \
y = find(y).parent; \
if (x == y) \
return; \
if (rank[x] < rank[y]) { \
pp_foreach(pp_gen_unite_set, __VA_ARGS__); \
nodes[x].parent = y; \
} else { \
pp_foreach(pp_gen_unite_set, __VA_ARGS__); \
nodes[y].parent = x; \
if (rank[x] == rank[y]) \
rank[x]++; \
} \
} \
bool same(int x, int y) { return find(x).parent == find(y).parent; } \
}
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 0 && c == 0)
cout << "Close" << endl;
else if (a == 0 && b == 1 && c == 0)
cout << "Close" << endl;
else if (a == 1 && b == 1 && c == 0)
cout << "Open" << endl;
else if (a == 0 && b == 0 && c == 1)
cout << "Open" << endl;
else if (a == 0 && b == 0 && c == 0)
cout << "Close" << endl;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 1,063
| 2
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1) {
if (b == 0) {
cout << "close" << endl;
} else {
cout << "open" << endl;
}
} else {
if (c == 1) {
cout << "open" << endl;
} else {
cout << "close" << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1) {
if (b == 0) {
cout << "Close" << endl;
} else {
cout << "Open" << endl;
}
} else {
if (c == 1) {
cout << "Open" << endl;
} else {
cout << "Close" << endl;
}
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 95
| 8
|
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string s;
getline(cin, s);
if (s == "1 1 0" || s == "0 0 1")
cout << "Open" << endl;
else
cout << "Closed" << endl;
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string s;
getline(cin, s);
if (s == "1 1 0" || s == "0 0 1")
cout << "Open" << endl;
else
cout << "Close" << endl;
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 59
| 2
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 0 && c == 0)
cout << "Close";
if (a == 0 && b == 1 && c == 0)
cout << "Close";
if (a == 1 && b == 1 && c == 0)
cout << "Open";
if (a == 0 && b == 0 && c == 1)
cout << "Open";
if (a == 0 && b == 0 && c == 0)
cout << "Open";
cout << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 1 && b == 0 && c == 0)
cout << "Close";
if (a == 0 && b == 1 && c == 0)
cout << "Close";
if (a == 1 && b == 1 && c == 0)
cout << "Open";
if (a == 0 && b == 0 && c == 1)
cout << "Open";
if (a == 0 && b == 0 && c == 0)
cout << "Close";
cout << endl;
return 0;
}
|
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6]]
| 1
| 134
| 2
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// common
typedef long long i64, ll;
#define BR "\n"
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, l, r) for (int i = (l); i < (int)(r); ++i)
#define EACH(it, o) for (auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l, v, r) ((l) <= (v) && (v) < (r))
// debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp, act)
#define STOP(e)
#else
#define DUMP(x) cerr << #x << " = " << (x)
#define DUMPLN(x) DUMP(x) << endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x) << endl
#define LINE() cerr << " (L" << __LINE__ << ")"
#define LINELN() LINE() << endl
#define CHECK(exp, act) \
if (exp != act) { \
DUMPLN(exp); \
DEBUGLN(act); \
}
#define STOP(e) \
CHECK(e, true); \
if (!(e)) \
exit(1);
#endif
template <class T> inline string toString(const vector<T> &x) {
stringstream ss;
REP(i, x.size()) {
if (i != 0)
ss << " ";
ss << x[i];
}
return ss.str();
}
template <class T> inline string toString(const vector<vector<T>> &map) {
stringstream ss;
REP(i, map.size()) {
if (i != 0)
ss << BR;
ss << toString(map[i]);
}
return ss.str();
}
template <class K, class V> string toString(map<K, V> &x) {
string res;
stringstream ss;
for (auto &p : x)
ss << p.first << ":" << p.second << " ";
return ss.str();
}
string BITtoString(int bit) {
stringstream ss;
while (bit != 0) {
ss << (bit % 2);
bit /= 2;
}
string res = ss.str();
reverse(ALL(res));
return res;
}
template <typename T, typename V> inline T pmod(T v, V MOD) {
return (v % MOD + MOD) % MOD;
}
class Main {
public:
void run() {
int b1, b2, b3;
cin >> b1 >> b2 >> b3;
if (b1 & b2 & !b3)
cout << "Open" << endl;
if (!b1 & !b2 & b3)
cout << "Open" << endl;
cout << "Close" << endl;
}
};
int main() {
// ios::sync_with_stdio(false);
Main().run();
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// common
typedef long long i64, ll;
#define BR "\n"
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, l, r) for (int i = (l); i < (int)(r); ++i)
#define EACH(it, o) for (auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l, v, r) ((l) <= (v) && (v) < (r))
// debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp, act)
#define STOP(e)
#else
#define DUMP(x) cerr << #x << " = " << (x)
#define DUMPLN(x) DUMP(x) << endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x) << endl
#define LINE() cerr << " (L" << __LINE__ << ")"
#define LINELN() LINE() << endl
#define CHECK(exp, act) \
if (exp != act) { \
DUMPLN(exp); \
DEBUGLN(act); \
}
#define STOP(e) \
CHECK(e, true); \
if (!(e)) \
exit(1);
#endif
template <class T> inline string toString(const vector<T> &x) {
stringstream ss;
REP(i, x.size()) {
if (i != 0)
ss << " ";
ss << x[i];
}
return ss.str();
}
template <class T> inline string toString(const vector<vector<T>> &map) {
stringstream ss;
REP(i, map.size()) {
if (i != 0)
ss << BR;
ss << toString(map[i]);
}
return ss.str();
}
template <class K, class V> string toString(map<K, V> &x) {
string res;
stringstream ss;
for (auto &p : x)
ss << p.first << ":" << p.second << " ";
return ss.str();
}
string BITtoString(int bit) {
stringstream ss;
while (bit != 0) {
ss << (bit % 2);
bit /= 2;
}
string res = ss.str();
reverse(ALL(res));
return res;
}
template <typename T, typename V> inline T pmod(T v, V MOD) {
return (v % MOD + MOD) % MOD;
}
class Main {
public:
void run() {
int b1, b2, b3;
cin >> b1 >> b2 >> b3;
if (b1 & b2 & !b3)
cout << "Open" << endl;
else if (!b1 & !b2 & b3)
cout << "Open" << endl;
else
cout << "Close" << endl;
}
};
int main() {
// ios::sync_with_stdio(false);
Main().run();
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 57, 75, 76, 0, 57, 75, 76, 0, 95]]
| 1
| 548
| 2
|
while True:
try:
ticket = input().split()
if ticket[2] == "1":
print("Open")
elif ticket[0] == ticket[1] and ticket[0] == "0":
print("Open")
else:
print("Close")
except:
exit()
|
while True:
try:
ticket = input().split()
if ticket[2] == "1":
print("Open")
elif ticket[0] == ticket[1] and ticket[0] == "1":
print("Open")
else:
print("Close")
except:
exit()
|
[["-", 75, 665, 15, 679, 12, 666, 0, 557, 0, 6], ["+", 75, 665, 15, 679, 12, 666, 0, 557, 0, 6]]
| 5
| 69
| 2
|
m=[0,1,0,0,0,0,1,0]
(a, b, c) = list(map(int, input().split()))
print(["Close", "Open"][a * 4 + b * 2 + c])
|
m=[0,1,0,0,0,0,1,0]
(a, b, c) = list(map(int, input().split()))
print(["Close", "Open"][m[a * 4 + b * 2 + c]])
|
[["+", 0, 652, 3, 4, 0, 206, 206, 206, 51, 22], ["+", 0, 652, 3, 4, 0, 206, 206, 206, 0, 70], ["+", 0, 652, 3, 4, 0, 206, 206, 206, 0, 73]]
| 5
| 65
| 3
|
import java.util.*;
class Main {
int n;
int[] h = new int[101];
Main() {
Scanner sc = new Scanner(System.in);
while (true) {
n = sc.nextInt();
if (n == 0) {
break;
}
for (int i = 0; i < n + 1; i++) {
h[i] = sc.nextInt();
}
for (int i = 0; i < n + 1; i++) {
int[] a = new int[101];
int b = 0;
for (int j = 0; j < n + 1; j++) {
if (i != j) {
a[b] = h[j];
b++;
}
}
boolean flg = true;
int key = a[1] - a[0];
for (int j = 1; j < n; j++) {
if (key != a[j] - a[j - 1])
flg = false;
}
if (flg)
System.out.println(h[i]);
}
}
}
public static void main(String[] args) { new Main(); }
}
|
import java.util.*;
class Main {
int n;
int[] h = new int[101];
Main() {
Scanner sc = new Scanner(System.in);
while (true) {
n = sc.nextInt();
if (n == 0) {
break;
}
for (int i = 0; i < n + 1; i++) {
h[i] = sc.nextInt();
}
for (int i = 0; i < n + 1; i++) {
int[] a = new int[101];
int b = 0;
for (int j = 0; j < n + 1; j++) {
if (i != j) {
a[b] = h[j];
b++;
}
}
boolean flg = true;
int key = a[1] - a[0];
for (int j = 1; j < n; j++) {
if (key != a[j] - a[j - 1])
flg = false;
}
if (flg) {
System.out.println(h[i]);
break;
}
}
}
}
public static void main(String[] args) { new Main(); }
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 3
| 254
| 4
|
#include <stdio.h>
int main(void) {
int n, h[101];
int i, j, k;
int sa[101], b[101];
int flg;
scanf("%d", &n);
while (n != 0) {
for (i = 0; i < n + 1; i++) {
scanf("%d", &h[i]);
}
for (i = 0; i < n + 1; i++) {
k = 0;
for (j = 0; j < n + 1; j++) {
if (i != j) {
b[k] = h[j];
k++;
}
}
for (j = 0; j < n - 1; j++) {
sa[j] = b[j + 1] - b[j];
}
flg = 0;
for (j = 0; j < n - 2; j++) {
if (sa[j] != sa[j + 1]) {
flg = 1;
}
}
if (flg == 0) {
printf("%d\n", h[i]);
}
}
scanf("%d", &n);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, h[101];
int i, j, k;
int sa[101], b[101];
int flg;
scanf("%d", &n);
while (n != 0) {
for (i = 0; i < n + 1; i++) {
scanf("%d", &h[i]);
}
for (i = 0; i < n + 1; i++) {
k = 0;
for (j = 0; j < n + 1; j++) {
if (i != j) {
b[k] = h[j];
k++;
}
}
for (j = 0; j < n - 1; j++) {
sa[j] = b[j + 1] - b[j];
}
flg = 0;
for (j = 0; j < n - 2; j++) {
if (sa[j] != sa[j + 1]) {
flg = 1;
}
}
if (flg == 0) {
printf("%d\n", h[i]);
break;
}
}
scanf("%d", &n);
}
return 0;
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
| 0
| 254
| 2
|
#include <stdio.h>
int main(void) {
int i, w, cnt, n, h[101], sa[5];
while (scanf("%d", &n), n != 0) {
for (i = 0; i <= n; i++)
scanf("%d", &h[i]);
sa[0] = h[1] - h[0];
sa[1] = h[i - 1] - h[i - 2];
sa[2] = h[(i - 1) / 2] - h[(i - 1) / 2 - 1];
sa[3] = h[(i - 1) / 2 + 1] - h[(i - 1) / 2];
if (sa[0] == sa[1] || sa[1] == sa[2] || sa[1] == sa[3])
sa[4] = sa[1];
if (sa[0] == sa[2] || sa[0] == sa[3])
sa[4] = sa[0];
for (i = 1; i <= n; i++) {
if (h[i] - h[i - 1] != sa[4]) {
cnt++;
if (cnt > 1)
w = h[i - 1];
if (h[i + 1] - h[i] == sa[4])
w = h[i - 1];
if (i == n && w < 1)
w = h[i];
}
}
printf("%d\n", w);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int i, w, cnt, n, h[101], sa[5];
while (scanf("%d", &n), n != 0) {
for (i = cnt = w = 0; i <= n; i++)
scanf("%d", &h[i]);
sa[0] = h[1] - h[0];
sa[1] = h[i - 1] - h[i - 2];
sa[2] = h[(i - 1) / 2] - h[(i - 1) / 2 - 1];
sa[3] = h[(i - 1) / 2 + 1] - h[(i - 1) / 2];
if (sa[0] == sa[1] || sa[1] == sa[2] || sa[1] == sa[3])
sa[4] = sa[1];
if (sa[0] == sa[2] || sa[0] == sa[3])
sa[4] = sa[0];
for (i = 1; i <= n; i++) {
if (h[i] - h[i - 1] != sa[4]) {
cnt++;
if (cnt > 1)
w = h[i - 1];
if (h[i + 1] - h[i] == sa[4])
w = h[i - 1];
if (i == n && w < 1)
w = h[i];
}
}
printf("%d\n", w);
}
return 0;
}
|
[["+", 8, 9, 0, 7, 10, 11, 12, 11, 31, 22], ["+", 8, 9, 0, 7, 10, 11, 12, 11, 17, 32], ["+", 0, 7, 10, 11, 12, 11, 12, 11, 31, 22], ["+", 0, 7, 10, 11, 12, 11, 12, 11, 17, 32]]
| 0
| 350
| 4
|
#include <iostream>
using namespace std;
int n;
int a[101], b[100];
main() {
while (cin >> n, n) {
for (int i = 0; i < n + 1; i++)
cin >> a[i];
for (int i = 0; i < n + 1; i++) {
bool f = 1;
int c = 0;
for (int j = 0; j < n + 1; j++)
if (i != j)
b[c++] = a[j];
int p = b[1] - b[0];
for (int j = 1; j < n - 1; j++)
f &= p == b[j + 1] - b[j];
if (f)
cout << a[i] << endl;
}
}
}
|
#include <iostream>
using namespace std;
int n;
int a[101], b[100];
main() {
while (cin >> n, n) {
for (int i = 0; i < n + 1; i++)
cin >> a[i];
for (int i = 0; i < n + 1; i++) {
bool f = 1;
int c = 0;
for (int j = 0; j < n + 1; j++)
if (i != j)
b[c++] = a[j];
int p = b[1] - b[0];
for (int j = 1; j < n - 1; j++)
f &= p == b[j + 1] - b[j];
if (f) {
cout << a[i] << endl;
break;
}
}
}
}
|
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 177
| 4
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define dep(i, a, n) for (int i = a; i >= (n); i--)
#define FOR(i, a, n) for (int i = a; i < (n); i++)
#define mod (ll)(1e9 + 7)
#define int ll
#define INF 100000000
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
bool check(vector<int> &ch) {
ll tmp = ch[1] - ch[0];
FOR(i, 1, ch.size() - 1) {
if (ch[i + 1] - ch[i] != tmp)
return false;
}
return true;
}
signed main() {
ll n, s[101];
while (1) {
cin >> n;
if (n == 0)
break;
rep(i, n + 1) cin >> s[i];
rep(i, n + 1) {
vector<int> ch;
rep(j, n + 1) {
if (i == j)
continue;
ch.pb(s[j]);
}
if (check(ch)) {
cout << s[i] << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define dep(i, a, n) for (int i = a; i >= (n); i--)
#define FOR(i, a, n) for (int i = a; i < (n); i++)
#define mod (ll)(1e9 + 7)
#define int ll
#define INF 100000000
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
bool check(vector<int> &ch) {
ll tmp = ch[1] - ch[0];
FOR(i, 1, ch.size() - 1) {
if (ch[i + 1] - ch[i] != tmp)
return false;
}
return true;
}
signed main() {
ll n, s[101];
while (1) {
cin >> n;
if (n == 0)
break;
rep(i, n + 1) cin >> s[i];
rep(i, n + 1) {
vector<int> ch;
rep(j, n + 1) {
if (i == j)
continue;
ch.pb(s[j]);
}
if (check(ch)) {
cout << s[i] << endl;
break;
}
}
}
return 0;
}
|
[["+", 0, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 265
| 2
|
#include <cassert>
#include <ccomplex>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctgmath>
#include <ctime>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
struct edge {
int to, cost;
};
// typedef pair<int,int> P;
bool isupper(char c) {
if ('A' <= c && c <= 'Z')
return 1;
return 0;
}
bool islower(char c) {
if ('a' <= c && c <= 'z')
return 1;
return 0;
}
bool isPrime(int x) {
if (x == 1)
return 0;
if (x == 2)
return 1;
if (x % 2 == 0)
return 0;
for (int i = 3; i * i <= x; i++)
if (x % i == 0)
return 0;
return 1;
}
bool iskaibun(string s) {
for (int i = 0; i < s.size() / 2; i++)
if (s[i] != s[s.size() - i - 1])
return 0;
return 1;
}
bool isnumber(char c) { return ('0' <= c && c <= '9'); }
bool isalpha(char c) { return (isupper(c) && islower(c)); }
void printvi(vector<int> v) {
rep(i, 0, v.size()) {
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
}
void printvil(vector<int> v) {
rep(i, 0, v.size()) { cout << v[i] << endl; }
}
void printvvi(vector<vector<int>> v) {
rep(i, 0, v.size()) {
rep(j, 0, v[i].size()) {
if (j)
cout << " ";
cout << v[i][j];
}
cout << endl;
}
}
void printvstr(vector<string> v) {
rep(i, 0, v.size()) { cout << v[i] << endl; }
}
signed main() {
int n;
while (1) {
cin >> n;
if (n == 0)
break;
n++;
vector<int> v2(n);
rep(i, 0, n) cin >> v2[i];
rep(j, 0, n) {
vector<int> v = v2;
v.erase(v.begin() + j);
// printvi(v);
bool ok = true;
int diff = 0;
rep(i, 1, n - 1) {
if (i == 1)
diff = v[i] - v[i - 1];
else {
if (v[i] - v[i - 1] != diff) {
ok = false;
// cout<<"debug "<<i<<" "<<v[i]<<" "<<v[i-1]<<endl;
}
}
}
// cout<<ok<<endl;
if (ok) {
cout << v[j] << endl;
break;
}
}
}
}
/*
*/
|
#include <cassert>
#include <ccomplex>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctgmath>
#include <ctime>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
struct edge {
int to, cost;
};
// typedef pair<int,int> P;
bool isupper(char c) {
if ('A' <= c && c <= 'Z')
return 1;
return 0;
}
bool islower(char c) {
if ('a' <= c && c <= 'z')
return 1;
return 0;
}
bool isPrime(int x) {
if (x == 1)
return 0;
if (x == 2)
return 1;
if (x % 2 == 0)
return 0;
for (int i = 3; i * i <= x; i++)
if (x % i == 0)
return 0;
return 1;
}
bool iskaibun(string s) {
for (int i = 0; i < s.size() / 2; i++)
if (s[i] != s[s.size() - i - 1])
return 0;
return 1;
}
bool isnumber(char c) { return ('0' <= c && c <= '9'); }
bool isalpha(char c) { return (isupper(c) && islower(c)); }
void printvi(vector<int> v) {
rep(i, 0, v.size()) {
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
}
void printvil(vector<int> v) {
rep(i, 0, v.size()) { cout << v[i] << endl; }
}
void printvvi(vector<vector<int>> v) {
rep(i, 0, v.size()) {
rep(j, 0, v[i].size()) {
if (j)
cout << " ";
cout << v[i][j];
}
cout << endl;
}
}
void printvstr(vector<string> v) {
rep(i, 0, v.size()) { cout << v[i] << endl; }
}
signed main() {
int n;
while (1) {
cin >> n;
if (n == 0)
break;
n++;
vector<int> v2(n);
rep(i, 0, n) cin >> v2[i];
rep(j, 0, n) {
vector<int> v = v2;
v.erase(v.begin() + j);
// printvi(v);
bool ok = true;
int diff = 0;
rep(i, 1, n - 1) {
if (i == 1)
diff = v[i] - v[i - 1];
else {
if (v[i] - v[i - 1] != diff) {
ok = false;
// cout<<"debug "<<i<<" "<<v[i]<<" "<<v[i-1]<<endl;
}
}
}
// cout<<ok<<endl;
if (ok) {
cout << v2[j] << endl;
break;
}
}
}
}
/*
*/
|
[["-", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22]]
| 1
| 870
| 2
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int n;
int h[102];
bool ok(vector<int> &vec) {
int d = vec[0] - vec[1];
rep(i, vec.size()) {
if (i == 0)
continue;
if (vec[i - 1] - vec[i] != d)
return false;
}
return true;
}
void solve() {
rep(i, n + 1) cin >> h[i];
rep(i, n + 1) {
vector<int> vec;
rep(j, n + 1) {
if (i != j)
vec.pb(h[j]);
}
if (ok(vec)) {
cout << h[i] << endl;
}
}
}
int main() {
while (cin >> n) {
if (n == 0)
break;
solve();
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int n;
int h[102];
bool ok(vector<int> &vec) {
int d = vec[0] - vec[1];
rep(i, vec.size()) {
if (i == 0)
continue;
if (vec[i - 1] - vec[i] != d)
return false;
}
return true;
}
void solve() {
rep(i, n + 1) cin >> h[i];
rep(i, n + 1) {
vector<int> vec;
rep(j, n + 1) {
if (i != j)
vec.pb(h[j]);
}
if (ok(vec)) {
cout << h[i] << endl;
break;
}
}
}
int main() {
while (cin >> n) {
if (n == 0)
break;
solve();
}
return 0;
}
|
[["+", 0, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 316
| 2
|
#include <cstdio>
#include <vector>
using namespace std;
int h[101];
int main() {
int n;
while (scanf("%d", &n), n) {
for (int i = 0; i <= n; i++) {
scanf("%d", &h[i]);
}
for (int i = 0; i <= n; i++) {
vector<int> v;
for (int j = 0; j <= n; j++) {
if (i != j)
v.push_back(h[j]);
}
int d = h[1] - h[0];
bool OK = 1;
for (int i = 2; i < n; i++) {
if (v[i] != v[i - 1] + d) {
OK = 0;
break;
}
}
if (OK) {
printf("%d\n", h[i]);
break;
}
}
}
}
|
#include <cstdio>
#include <vector>
using namespace std;
int h[101];
int main() {
int n;
while (scanf("%d", &n), n) {
for (int i = 0; i <= n; i++) {
scanf("%d", &h[i]);
}
for (int i = 0; i <= n; i++) {
vector<int> v;
for (int j = 0; j <= n; j++) {
if (i != j)
v.push_back(h[j]);
}
int d = v[1] - v[0];
bool OK = 1;
for (int i = 2; i < n; i++) {
if (v[i] != v[i - 1] + d) {
OK = 0;
break;
}
}
if (OK) {
printf("%d\n", h[i]);
break;
}
}
}
}
|
[["-", 0, 43, 49, 50, 51, 16, 31, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 16, 31, 69, 28, 22], ["-", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22]]
| 1
| 201
| 4
|
#include <iostream>
#include <vector>
using namespace std;
int n, a[1000], s;
vector<int> p;
int main() {
while (true) {
cin >> n;
if (!n) {
break;
}
for (int i = 0; i < n + 1; i++) {
cin >> a[i];
}
for (int i = 0; i < n + 1; i++) {
p.clear();
for (int j = 0; j < n + 1; j++) {
if (i != j) {
p.push_back(a[j]);
}
}
for (int j = 0; j < p.size() - 1; j++) {
if (j == 0) {
s = a[j + 1] - a[j];
} else if (a[j + 1] - a[j] != s) {
goto E;
}
}
cout << a[i] << endl;
goto otawa;
E:;
}
otawa:;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
int n, a[1000], s;
vector<int> p;
int main() {
while (true) {
cin >> n;
if (!n) {
break;
}
for (int i = 0; i < n + 1; i++) {
cin >> a[i];
}
for (int i = 0; i < n + 1; i++) {
p.clear();
for (int j = 0; j < n + 1; j++) {
if (i != j) {
p.push_back(a[j]);
}
}
for (int j = 0; j < p.size() - 1; j++) {
if (j == 0) {
s = p[j + 1] - p[j];
} else if (p[j + 1] - p[j] != s) {
goto E;
}
}
cout << a[i] << endl;
goto otawa;
E:;
}
otawa:;
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 69, 28, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 69, 28, 22], ["-", 15, 339, 51, 16, 31, 16, 31, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 16, 31, 69, 28, 22], ["-", 15, 339, 51, 16, 31, 16, 12, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 16, 12, 69, 28, 22]]
| 1
| 218
| 8
|
#include <iostream>
using namespace std;
int main() {
int n, a, c, j;
int b[105];
int s[105];
int i = 0;
while (cin >> n && n) {
n++;
for (j = 0; j < n; j++) {
cin >> b[j];
}
c = b[1] - b[0];
for (j = 1; j < n - 1; j++) {
if (c != b[j + 1] - b[j]) {
if (j == 1) {
c = b[4] - b[3];
a = b[1] - b[0];
if (c != a) {
if (c == b[2] - b[0]) {
j = 0;
} else {
j = -1;
}
}
}
if (j == 2) {
if (b[1] - b[0] == b[2] - b[1]) {
j = 0;
}
}
j++;
break;
}
}
s[i] = b[j];
i++;
}
for (j = 0; j < i; j++) {
cout << s[j] << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, a, c, j;
int b[105];
int s[505];
int i = 0;
while (cin >> n && n) {
n++;
for (j = 0; j < n; j++) {
cin >> b[j];
}
c = b[1] - b[0];
for (j = 1; j < n - 1; j++) {
if (c != b[j + 1] - b[j]) {
if (j == 1) {
c = b[4] - b[3];
a = b[1] - b[0];
if (c != a) {
if (c == b[2] - b[0]) {
j = 0;
} else {
j = -1;
}
}
}
if (j == 2) {
if (b[2] - b[0] == b[4] - b[3]) {
j = 0;
}
}
j++;
break;
}
}
s[i] = b[j];
i++;
}
for (j = 0; j < i; j++) {
cout << s[j] << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 51, 16, 31, 16, 31, 69, 341, 342, 0, 13], ["+", 51, 16, 31, 16, 31, 69, 341, 342, 0, 13], ["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 13], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 13], ["-", 51, 16, 12, 16, 12, 69, 341, 342, 0, 13], ["+", 51, 16, 12, 16, 12, 69, 341, 342, 0, 13]]
| 1
| 268
| 8
|
/*
* src.cpp
*
* Created on: 2016/08/08
* Author: joi
*/
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
const int MAX_N = 1e2;
int N;
int H[MAX_N + 1];
vector<int> vec;
int main() {
do {
scanf("%d", &N);
if (N) {
REP(i, N + 1) { scanf("%d", &H[i]); }
REP(i, N + 1) {
vec.clear();
REP(j, N + 1) {
if (i != j) {
vec.push_back(H[j]);
}
}
int d = vec[1] - vec[0];
bool flg = true;
FOR(k, 1, (int)vec.size() - 1) {
if (d != vec[k + 1] - vec[k]) {
flg = false;
}
}
if (flg) {
printf("%d\n", H[i]);
}
}
}
} while (N);
return 0;
}
|
/*
* src.cpp
*
* Created on: 2016/08/08
* Author: joi
*/
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
const int MAX_N = 1e2;
int N;
int H[MAX_N + 1];
vector<int> vec;
int main() {
do {
scanf("%d", &N);
if (N) {
REP(i, N + 1) { scanf("%d", &H[i]); }
REP(i, N + 1) {
vec.clear();
REP(j, N + 1) {
if (i != j) {
vec.push_back(H[j]);
}
}
int d = vec[1] - vec[0];
bool flg = true;
FOR(k, 1, (int)vec.size() - 1) {
if (d != vec[k + 1] - vec[k]) {
flg = false;
}
}
if (flg) {
printf("%d\n", H[i]);
i = N + 1;
}
}
}
} while (N);
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 0, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 230
| 6
|
#include <stdio.h>
int t[101];
int c[100];
int main() {
int a;
while (scanf("%d", &a), a) {
for (int i = 0; i <= a; i++) {
scanf("%d", t + i);
}
for (int i = 0; i <= a; i++) {
int I = 0;
for (int j = 0; j <= a; j++)
if (i != j)
c[I++] = t[j];
bool ok = true;
for (int j = 1; j < a; j++)
if (c[1] - c[0] != c[j] - c[j - 1])
ok = false;
if (c[1] <= c[0])
ok = false;
if (ok)
printf("%d\n", t[i]);
}
}
}
|
#include <stdio.h>
int t[101];
int c[100];
int main() {
int a;
while (scanf("%d", &a), a) {
for (int i = 0; i <= a; i++) {
scanf("%d", t + i);
}
for (int i = 0; i <= a; i++) {
int I = 0;
for (int j = 0; j <= a; j++)
if (i != j)
c[I++] = t[j];
bool ok = true;
for (int j = 1; j < a; j++)
if (c[1] - c[0] != c[j] - c[j - 1])
ok = false;
if (c[1] <= c[0])
ok = false;
if (ok) {
printf("%d\n", t[i]);
break;
}
}
}
}
|
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 198
| 4
|
#include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> naes;
bool isSequense(vector<int> &data) {
int sa = data[1] - data[0];
for (int i = 0; i < n - 2; i++) {
if (data[i + 1] - data[i] != sa)
return false;
}
return true;
}
int solve() {
for (int i = 0; i < n; i++) {
vector<int> tmp = naes;
tmp.erase(tmp.begin() + i);
if (isSequense(tmp))
return naes[i];
}
}
int main() {
while (cin >> n && n) {
naes.resize(n);
for (int i = 0; i < n; i++) {
cin >> naes[i];
}
cout << solve() << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> naes;
bool isSequense(vector<int> &data) {
int sa = data[1] - data[0];
for (int i = 0; i < n - 2; i++) {
if (data[i + 1] - data[i] != sa)
return false;
}
return true;
}
int solve() {
for (int i = 0; i < n; i++) {
vector<int> tmp = naes;
tmp.erase(tmp.begin() + i);
if (isSequense(tmp))
return naes[i];
}
}
int main() {
while (cin >> n && n) {
n++;
naes.resize(n);
for (int i = 0; i < n; i++) {
cin >> naes[i];
}
cout << solve() << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 195
| 3
|
#include <bits/stdc++.h>
using namespace std;
bool solve(vector<int> v, int idx) {
v.erase(v.begin() + idx);
int diff = v[1] - v[0];
for (int i = 0; i < (int)v.size() - 1; i++) {
if (diff != v[i + 1] - v[i])
return false;
}
return true;
}
int main() {
int n;
while (cin >> n, n) {
vector<int> v(n + 1);
for (int i = 0; i < n + 1; i++)
cin >> v[i];
for (int i = 0; i < n + 1; i++) {
bool ret = solve(v, i);
if (ret)
cout << v[i] << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool solve(vector<int> v, int idx) {
v.erase(v.begin() + idx);
int diff = v[1] - v[0];
for (int i = 0; i < (int)v.size() - 1; i++) {
if (diff != v[i + 1] - v[i])
return false;
}
return true;
}
int main() {
int n;
while (cin >> n, n) {
vector<int> v(n + 1);
for (int i = 0; i < n + 1; i++)
cin >> v[i];
for (int i = 0; i < n + 1; i++) {
bool ret = solve(v, i);
if (ret) {
cout << v[i] << endl;
break;
}
}
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 190
| 4
|
while True:
n = eval(input())
if n == 0: break
a = list(map(int,input().split()))
da = [a[i+1] - a[i] for i in range(n)]
d = sorted(list(set(da)), key = lambda x:da.count(x))[1]
for i in range(n):
if i == 0 and a[i] + d != a[i+1]:
if a[i] + 2*d == a[i+2]:
print(a[i+1])
else:
print(a[i])
break
elif a[i] + d != a[i+1]:
print(a[i+1])
break
|
while True:
n = eval(input())
if n == 0: break
a = list(map(int,input().split()))
da = [a[i+1] - a[i] for i in range(n)]
d = sorted(list(set(da)), key = lambda x:da.count(x))[-1]
for i in range(n):
if i == 0 and a[i] + d != a[i+1]:
if a[i+1] + d != a[i+2]:
print(a[i+1])
else:
print(a[i])
break
elif a[i] + d != a[i+1]:
print(a[i+1])
break
|
[["+", 0, 1, 0, 662, 12, 206, 206, 664, 17, 33], ["+", 15, 666, 0, 657, 31, 206, 206, 657, 17, 72], ["+", 15, 666, 0, 657, 31, 206, 206, 657, 12, 612], ["-", 0, 57, 15, 666, 0, 657, 12, 657, 31, 612], ["-", 0, 57, 15, 666, 0, 657, 12, 657, 17, 48], ["-", 0, 57, 64, 196, 0, 57, 15, 666, 667, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 79]]
| 5
| 171
| 7
|
#include <stdio.h>
int main(void) {
int N;
int a[4];
int L, S;
int i, j, cnt, tmp;
while (scanf("%d", &N) != EOF) {
if (N == 0000) {
break;
} else if (N % 1111 == 0) {
printf("NA\n");
} else {
cnt = 0;
while (N != 6174) {
a[0] = N / 1000;
a[1] = N / 100 % 10;
a[2] = N / 10 % 10;
a[3] = N % 10;
for (i = 0; i < 4; i++) {
for (j = 1; j < 4; j++) {
if (a[j - 1] < a[j]) {
tmp = a[j];
a[j] = a[j - 1];
a[j - 1] = tmp;
}
}
}
L = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
for (i = 0; i < 4; i++) {
for (j = 1; j < 4; j++) {
if (a[j - 1] > a[j]) {
tmp = a[j];
a[j] = a[j - 1];
a[j - 1] = tmp;
}
}
}
S = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
N = L - S;
cnt++;
}
}
printf("%d\n", cnt);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int N;
int a[4];
int L, S;
int i, j, cnt, tmp;
while (scanf("%d", &N) != EOF) {
if (N == 0000) {
break;
} else if (N % 1111 == 0) {
printf("NA\n");
} else {
cnt = 0;
while (N != 6174) {
a[0] = N / 1000;
a[1] = N / 100 % 10;
a[2] = N / 10 % 10;
a[3] = N % 10;
for (i = 0; i < 4; i++) {
for (j = 1; j < 4; j++) {
if (a[j - 1] < a[j]) {
tmp = a[j];
a[j] = a[j - 1];
a[j - 1] = tmp;
}
}
}
L = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
for (i = 0; i < 4; i++) {
for (j = 1; j < 4; j++) {
if (a[j - 1] > a[j]) {
tmp = a[j];
a[j] = a[j - 1];
a[j - 1] = tmp;
}
}
}
S = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
N = L - S;
cnt++;
}
printf("%d\n", cnt);
}
}
return (0);
}
|
[["-", 75, 76, 0, 57, 75, 76, 0, 9, 0, 46], ["+", 75, 76, 0, 57, 75, 76, 0, 9, 0, 46]]
| 0
| 360
| 2
|
#include <stdio.h>
#include <string.h>
int lower(char *a, char *b) { return *a - *b; }
int upper(char *a, char *b) { return *b - *a; }
int main(void) {
char num[8];
char lnum[8];
char unum[8];
int c;
while (~scanf("%s", num)) {
c = 0;
while (atoi(num) != 6174) {
if (atoi(num) % 1111 == 0) {
c = -1;
break;
}
strcpy(lnum, num);
qsort(lnum, 4, 1, lower);
strcpy(unum, num);
qsort(unum, 4, 1, upper);
sprintf(num, "%04d", atoi(unum) - atoi(lnum));
c++;
}
printf(~c ? "%d\n" : "NA\n", c);
}
return (0);
}
|
#include <stdio.h>
#include <string.h>
int lower(char *a, char *b) { return *a - *b; }
int upper(char *a, char *b) { return *b - *a; }
int main(void) {
char num[8];
char lnum[8];
char unum[8];
int c;
while (scanf("%s", num), atoi(num)) {
c = 0;
while (atoi(num) != 6174) {
if (atoi(num) % 1111 == 0) {
c = -1;
break;
}
strcpy(lnum, num);
qsort(lnum, 4, 1, lower);
strcpy(unum, num);
qsort(unum, 4, 1, upper);
sprintf(num, "%04d", atoi(unum) - atoi(lnum));
c++;
}
printf(~c ? "%d\n" : "NA\n", c);
}
return (0);
}
|
[["-", 8, 9, 0, 52, 15, 23, 0, 91, 17, 92], ["+", 15, 23, 0, 34, 31, 2, 3, 4, 0, 21], ["+", 15, 23, 0, 34, 31, 2, 3, 4, 0, 22], ["+", 15, 23, 0, 34, 31, 2, 3, 4, 0, 25], ["+", 0, 52, 15, 23, 0, 34, 12, 2, 63, 22], ["+", 15, 23, 0, 34, 12, 2, 3, 4, 0, 24]]
| 0
| 201
| 6
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int comp1(const void *a, const void *b) { return *(char *)a - *(char *)b; }
int comp2(const void *a, const void *b) { return *(char *)b - *(char *)a; }
int ctoi(char *s) {
return ((s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 +
(s[3] - '0') * 1);
}
int func(char *s) {
int a, b;
qsort(s, 4, sizeof(char), comp2);
a = ctoi(s);
qsort(s, 4, sizeof(char), comp1);
b = ctoi(s);
// printf("%d %d\n",a,b);
return (a - b);
}
int main() {
char n[9];
int i, ans, a;
while (1) {
scanf("%s", n);
if (strcmp(n, "0000") == 0)
break;
for (i = 0; i < 3; i++)
if (n[i] != n[i + 1])
break;
if (i == 3) {
printf("NA\n");
continue;
}
ans = 0;
while (ctoi(n) != 6174 && ans < 5) {
a = func(n);
n[0] = (a / 1000) % 10 + '0';
n[1] = (a / 100) % 10 + '0';
n[2] = (a / 10) % 10 + '0';
n[3] = (a / 1) % 10 + '0';
ans++;
}
printf("%d\n", ans);
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int comp1(const void *a, const void *b) { return *(char *)a - *(char *)b; }
int comp2(const void *a, const void *b) { return *(char *)b - *(char *)a; }
int ctoi(char *s) {
return ((s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 +
(s[3] - '0') * 1);
}
int func(char *s) {
int a, b;
qsort(s, 4, sizeof(char), comp2);
a = ctoi(s);
qsort(s, 4, sizeof(char), comp1);
b = ctoi(s);
// printf("%d %d\n",a,b);
return (a - b);
}
int main() {
char n[9];
int i, ans, a;
while (1) {
scanf("%s", n);
if (strcmp(n, "0000") == 0)
break;
for (i = 0; i < 3; i++)
if (n[i] != n[i + 1])
break;
if (i == 3) {
printf("NA\n");
continue;
}
ans = 0;
while (ctoi(n) != 6174) {
a = func(n);
n[0] = (a / 1000) % 10 + '0';
n[1] = (a / 100) % 10 + '0';
n[2] = (a / 10) % 10 + '0';
n[3] = (a / 1) % 10 + '0';
ans++;
}
printf("%d\n", ans);
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 98], ["-", 0, 52, 15, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 52, 15, 23, 0, 16, 12, 16, 17, 18], ["-", 0, 52, 15, 23, 0, 16, 12, 16, 12, 13]]
| 0
| 400
| 4
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n, l;
cin >> n;
while (n != 0) {
int nn[4] = {n % 10, (n / 10) % 10, (n / 100) % 10, (n / 1000) % 10};
if (nn[0] == nn[1] && nn[1] == nn[2] && nn[2] == nn[3]) {
cout << "NA" << endl;
} else {
int cou = 0;
while (nn[0] != 4 && nn[1] != 7 && nn[2] != 1 && nn[3] != 6) {
int rn[4];
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
if (nn[i] > nn[j]) {
int exi = nn[i];
nn[i] = nn[j];
nn[j] = exi;
}
}
}
for (int i = 0; i < 4; i++) {
rn[i] = nn[i];
}
for (int i = 0; i < 4; i++) {
if (rn[i] - nn[3 - i] < 0) {
rn[i] += 10;
rn[i] -= nn[3 - i];
rn[i + 1]--;
} else {
rn[i] -= nn[3 - i];
}
}
for (int i = 0; i < 4; i++) {
nn[i] = rn[i];
}
cou++;
}
cout << cou << endl;
}
cin >> n;
}
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n, l;
cin >> n;
while (n != 0) {
int nn[4] = {n % 10, (n / 10) % 10, (n / 100) % 10, (n / 1000) % 10};
// cout<<nn[3]<<nn[2]<<nn[1]<<nn[0]<<endl;
if (nn[0] == nn[1] && nn[1] == nn[2] && nn[2] == nn[3]) {
cout << "NA" << endl;
} else {
int cou = 0;
while (nn[0] != 4 || nn[1] != 7 || nn[2] != 1 || nn[3] != 6) {
int rn[4];
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
if (nn[i] > nn[j]) {
int exi = nn[i];
nn[i] = nn[j];
nn[j] = exi;
}
}
}
// cout<<nn[3]<<nn[2]<<nn[1]<<nn[0]<<'
// '<<nn[0]<<nn[1]<<nn[2]<<nn[3]<<endl;
for (int i = 0; i < 4; i++) {
rn[i] = nn[i];
}
for (int i = 0; i < 4; i++) {
if (rn[i] - nn[3 - i] < 0) {
rn[i] += 10;
rn[i] -= nn[3 - i];
rn[i + 1]--;
} else {
rn[i] -= nn[3 - i];
}
}
for (int i = 0; i < 4; i++) {
nn[i] = rn[i];
}
// cout<<nn[3]<<nn[2]<<nn[1]<<nn[0]<<endl;
cou++;
}
cout << cou << endl;
}
cin >> n;
}
return (0);
}
|
[["-", 15, 339, 51, 16, 31, 16, 31, 16, 17, 98], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 106], ["-", 0, 52, 15, 339, 51, 16, 31, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 106], ["-", 0, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 0, 9, 0, 52, 15, 339, 51, 16, 17, 106]]
| 1
| 374
| 6
|
#include <bits/stdc++.h>
using namespace std;
typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;
#define EACH(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define mod 1000000007
#define INF 100000000
#define fk first
#define sv second
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template <typename T> void print(const std::vector<T> &v, char sep = ' ') {
for (int i = 0; i < (int)v.size(); i++) {
if (i != 0)
cout << sep;
cout << v[i];
}
cout << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
while (cin >> n) {
int ct = 0;
if (n % 1111 == 0) {
cout << "NA\n";
continue;
}
while (n != 6174) {
int l, s, num[4];
REP(i, 4) {
num[i] = n % 10;
n /= 10;
}
sort(num, num + 4);
l = s = 0;
REP(i, 4) {
l = l * 10 + num[3 - i];
s = s * 10 + num[i];
}
n = l - s;
ct++;
}
cout << ct << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;
#define EACH(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define mod 1000000007
#define INF 100000000
#define fk first
#define sv second
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template <typename T> void print(const std::vector<T> &v, char sep = ' ') {
for (int i = 0; i < (int)v.size(); i++) {
if (i != 0)
cout << sep;
cout << v[i];
}
cout << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
while (cin >> n, n) {
int ct = 0;
if (n % 1111 == 0) {
cout << "NA\n";
continue;
}
while (n != 6174) {
int l, s, num[4];
REP(i, 4) {
num[i] = n % 10;
n /= 10;
}
sort(num, num + 4);
l = s = 0;
REP(i, 4) {
l = l * 10 + num[3 - i];
s = s * 10 + num[i];
}
n = l - s;
ct++;
}
cout << ct << endl;
}
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
| 1
| 367
| 2
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int N, S = 0;
while (1) {
cin >> N;
int big[4] = {0}, small[4], ans = 0;
if (N == 0000)
break;
if (N % 1111 == 0)
puts("NA");
else {
while (N != 6174) {
big[0] = small[0] = N / 1000;
big[1] = small[1] = (N - (big[0] * 1000)) / 100;
big[2] = small[2] = (N - (big[0] * 1000 + big[1] * 100)) / 10;
big[3] = small[3] = N % 10;
/*for(int i = 0; i < 4; i++)
{
cout << big[i] << "??¨" << small[i] << endl;
}*/
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 4; j++) {
if (big[i] > big[j])
swap(big[i], big[j]);
if (small[i] < small[j])
swap(small[i], small[j]);
}
}
N = 0;
S = 0;
int aaa = 1;
for (int i = 0; i < 4; i++) {
S += small[i] * aaa;
N += big[i] * aaa;
aaa = aaa * 10;
}
N -= S;
ans++;
}
}
cout << ans << endl;
}
}
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int N, S = 0;
while (1) {
cin >> N;
int big[4] = {0}, small[4], ans = 0;
if (N == 0000)
break;
if (N % 1111 == 0) {
puts("NA");
} else {
while (N != 6174) {
big[0] = small[0] = N / 1000;
big[1] = small[1] = (N - (big[0] * 1000)) / 100;
big[2] = small[2] = (N - (big[0] * 1000 + big[1] * 100)) / 10;
big[3] = small[3] = N % 10;
/*for(int i = 0; i < 4; i++)
{
cout << big[i] << "??¨" << small[i] << endl;
}*/
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 4; j++) {
if (big[i] > big[j])
swap(big[i], big[j]);
if (small[i] < small[j])
swap(small[i], small[j]);
}
}
N = 0;
S = 0;
int aaa = 1;
for (int i = 0; i < 4; i++) {
S += small[i] * aaa;
N += big[i] * aaa;
aaa = aaa * 10;
}
N -= S;
ans++;
}
cout << ans << endl;
}
}
}
|
[["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 75, 76, 0, 9, 0, 52, 8, 9, 0, 46], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 320
| 4
|
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int ans, used[1000010];
vector<P> in[1000010];
int n, m;
void check(int pos) {
if (used[pos] || ans)
return;
used[pos] = 1;
for (int i = 0; i < in[pos].size(); i++) {
int nx = in[pos][i].first, idx = in[pos][i].second;
if (used[nx])
ans = 0;
in[pos].erase(in[pos].begin() + i);
in[nx].erase(in[nx].begin() + idx);
check(nx);
i = -1;
}
}
int main() {
while (1) {
cin >> n >> m;
if (!n && !m)
break;
for (int i = 0; i <= n; i++)
in[i].clear(), used[i] = 0;
ans = 1;
for (int i = 0, a, b; i < m; i++) {
cin >> a >> b;
in[a].push_back(P(b, in[b].size()));
in[b].push_back(P(a, in[a].size() - 1));
if (in[a].size() / 3 || in[b].size() / 3)
ans = 0;
}
for (int i = 1; i <= n; i++)
check(i);
cout << (ans ? "yes" : "no") << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int ans, used[1000010];
vector<P> in[1000010];
int n, m;
void check(int pos) {
if (used[pos] || !ans)
return;
used[pos] = 1;
for (int i = 0; i < in[pos].size(); i++) {
int nx = in[pos][i].first, idx = in[pos][i].second;
if (used[nx])
ans = 0;
in[pos].erase(in[pos].begin() + i);
in[nx].erase(in[nx].begin() + idx);
check(nx);
i = -1;
}
}
int main() {
while (1) {
cin >> n >> m;
if (!n && !m)
break;
for (int i = 0; i <= n; i++)
in[i].clear(), used[i] = 0;
ans = 1;
for (int i = 0, a, b; i < m; i++) {
cin >> a >> b;
in[a].push_back(P(b, in[b].size()));
in[b].push_back(P(a, in[a].size() - 1));
if (in[a].size() / 3 || in[b].size() / 3)
ans = 0;
}
for (int i = 1; i <= n; i++)
check(i);
cout << (ans ? "yes" : "no") << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 91, 17, 111]]
| 1
| 371
| 1
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
bool check(const vector<vector<pair<int, int>>> &humans, int x, int y) {
for (int i = 0; i < 4; ++i) {
auto it = find(humans[i].begin(), humans[i].end(), make_pair(x, y));
if (it != humans[i].end())
return false;
}
return true;
}
int dx[] = {-1, 0, 1, 0, 0};
int dy[] = {0, 1, 0, -1, 0};
template <typename T> struct Compress {
map<T, int> mp;
map<int, T> revmp;
Compress(vector<T> vs) { setmp(vs); }
Compress() : mp(), revmp() {}
void setmp(vector<T> vs) {
sort(vs.begin(), vs.end());
vs.erase(unique(vs.begin(), vs.end()), vs.end());
for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
mp[vs[i]] = i;
revmp[i] = vs[i];
}
}
};
struct sale {
int id;
int d;
int s;
int e;
};
struct aa {
int flag;
int x;
int y;
int cost;
};
bool operator<(const vector<int> &l, const vector<int> &r) {
for (int i = 0; i < l.size(); ++i) {
if (l[i] < r[i])
return true;
else if (l[i] > r[i])
return false;
}
return false;
}
int solve(vector<int> haves, vector<int> nums) {
map<pair<vector<int>, int>, int> mp;
mp[make_pair(nums, 0)] = 1;
int ans = 1;
queue<pair<vector<int>, int>> que;
que.push(make_pair(nums, 0));
while (!que.empty()) {
auto atop(que.front());
que.pop();
int x = atop.second;
vector<int> v(atop.first);
int cost = mp[make_pair(atop.first, atop.second)];
ans = max(ans, cost);
for (int i = 0; i < haves.size(); ++i) {
if (v[i]) {
if (x + haves[i] >= 11) {
} else if (x + haves[i] == 10) {
v[i]--;
auto np = make_pair(v, 0);
if (mp[np] < cost + 1) {
mp[np] = cost + 1;
que.push(np);
}
v[i]++;
} else {
v[i]--;
auto np = make_pair(v, x + haves[i]);
if (mp[np] < cost) {
mp[np] = cost;
que.push(np);
}
v[i]++;
}
}
}
}
return ans - 1;
}
int dfs(const int now, const int pre, const vector<vector<int>> &edges,
vector<int> &memo) {
if (memo[now])
return false;
else {
memo[now] = true;
for (auto e : edges[now]) {
if (e != pre) {
int k = dfs(e, now, edges, memo);
if (!k)
return false;
}
}
}
return true;
}
int main() {
while (true) {
int N, M;
cin >> N >> M;
if (!N)
break;
vector<vector<int>> edges(N);
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
edges[a - 1].push_back(b);
edges[b - 1].push_back(a);
}
bool ok = all_of(edges.begin(), edges.end(),
[](const vector<int> &v) { return v.size() <= 2; });
vector<int> memo(N);
for (int i = 0; i < N; ++i) {
if (!memo[i]) {
int k = dfs(i, -1, edges, memo);
if (!k)
ok = false;
}
}
if (ok)
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
bool check(const vector<vector<pair<int, int>>> &humans, int x, int y) {
for (int i = 0; i < 4; ++i) {
auto it = find(humans[i].begin(), humans[i].end(), make_pair(x, y));
if (it != humans[i].end())
return false;
}
return true;
}
int dx[] = {-1, 0, 1, 0, 0};
int dy[] = {0, 1, 0, -1, 0};
template <typename T> struct Compress {
map<T, int> mp;
map<int, T> revmp;
Compress(vector<T> vs) { setmp(vs); }
Compress() : mp(), revmp() {}
void setmp(vector<T> vs) {
sort(vs.begin(), vs.end());
vs.erase(unique(vs.begin(), vs.end()), vs.end());
for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
mp[vs[i]] = i;
revmp[i] = vs[i];
}
}
};
struct sale {
int id;
int d;
int s;
int e;
};
struct aa {
int flag;
int x;
int y;
int cost;
};
bool operator<(const vector<int> &l, const vector<int> &r) {
for (int i = 0; i < l.size(); ++i) {
if (l[i] < r[i])
return true;
else if (l[i] > r[i])
return false;
}
return false;
}
int solve(vector<int> haves, vector<int> nums) {
map<pair<vector<int>, int>, int> mp;
mp[make_pair(nums, 0)] = 1;
int ans = 1;
queue<pair<vector<int>, int>> que;
que.push(make_pair(nums, 0));
while (!que.empty()) {
auto atop(que.front());
que.pop();
int x = atop.second;
vector<int> v(atop.first);
int cost = mp[make_pair(atop.first, atop.second)];
ans = max(ans, cost);
for (int i = 0; i < haves.size(); ++i) {
if (v[i]) {
if (x + haves[i] >= 11) {
} else if (x + haves[i] == 10) {
v[i]--;
auto np = make_pair(v, 0);
if (mp[np] < cost + 1) {
mp[np] = cost + 1;
que.push(np);
}
v[i]++;
} else {
v[i]--;
auto np = make_pair(v, x + haves[i]);
if (mp[np] < cost) {
mp[np] = cost;
que.push(np);
}
v[i]++;
}
}
}
}
return ans - 1;
}
int dfs(const int now, const int pre, const vector<vector<int>> &edges,
vector<int> &memo) {
if (memo[now])
return false;
else {
memo[now] = true;
for (auto e : edges[now]) {
if (e != pre) {
int k = dfs(e, now, edges, memo);
if (!k)
return false;
}
}
}
return true;
}
int main() {
while (true) {
int N, M;
cin >> N >> M;
if (!N)
break;
vector<vector<int>> edges(N);
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
edges[a - 1].push_back(b - 1);
edges[b - 1].push_back(a - 1);
}
bool ok = all_of(edges.begin(), edges.end(),
[](const vector<int> &v) { return v.size() <= 2; });
vector<int> memo(N);
for (int i = 0; i < N; ++i) {
if (!memo[i]) {
int k = dfs(i, -1, edges, memo);
if (!k)
ok = false;
}
}
if (ok)
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 1,041
| 4
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef double D;
typedef complex<D> P;
const D EPS = 1e-8;
D calc(const vector<P> &plg, D v) {
int n = plg.size();
int lt = n - 1, rt = 2;
D lx = 0, rx = real(plg[1]);
D y = 0;
while (1) {
D ny = min(imag(plg[lt]), imag(plg[rt]));
D nlx = lx + (ny - y) / (imag(plg[lt]) - y) * (real(plg[lt]) - lx);
D nrx = rx + (ny - y) / (imag(plg[rt]) - y) * (real(plg[rt]) - rx);
D w1 = rx - lx, w2 = nrx - nlx;
D h = ny - y;
D s = (w1 + w2) * h * 0.5;
if (s < v) {
v -= s;
y = ny;
lx = nlx;
rx = nrx;
if (imag(plg[lt]) == ny) {
--lt;
}
if (imag(plg[rt]) == ny) {
++rt;
}
assert(lt < rt);
} else {
D ret = y;
D a = (w2 - w1) / h * 0.5;
D b = w1;
D c = -v;
if (abs(a) > EPS) {
D d = b * b - 4 * a * c;
assert(d >= 0);
d = sqrt(d);
D t1 = (-b + d) / a * 0.5;
D t2 = (-b - d) / a * 0.5;
if (t1 > t2) {
swap(t1, t2);
}
assert(t2 >= 0);
if (t1 >= 0) {
ret += t1;
} else {
ret += t2;
}
} else {
D t = -c / b;
assert(t >= 0);
ret += t;
}
return ret;
}
}
}
int main() {
cout << fixed << setprecision(9);
ios::sync_with_stdio(false);
int n;
D d, v;
while (cin >> n >> d >> v, n) {
v /= d;
vector<P> pt(n), plg(n);
for (int i = 0; i < n; ++i) {
D x, y;
cin >> x >> y;
pt[i] = P(x, y);
}
D ans = -1;
for (int i = 0; i < n; ++i) {
P rot = polar(D(1), -arg(pt[(i + 1) % n] - pt[i]));
for (int j = 0; j < n; ++j) {
plg[j] = (pt[(i + j) % n] - pt[i]) * rot;
}
D t = calc(plg, v);
ans = max(ans, t);
}
cout << ans << '\n';
}
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef double D;
typedef complex<D> P;
const D EPS = 1e-8;
D calc(const vector<P> &plg, D v) {
int n = plg.size();
int lt = n - 1, rt = 2;
D lx = 0, rx = real(plg[1]);
D y = 0;
while (1) {
D ny = min(imag(plg[lt]), imag(plg[rt]));
D nlx = lx + (ny - y) / (imag(plg[lt]) - y) * (real(plg[lt]) - lx);
D nrx = rx + (ny - y) / (imag(plg[rt]) - y) * (real(plg[rt]) - rx);
D w1 = rx - lx, w2 = nrx - nlx;
D h = ny - y;
D s = (w1 + w2) * h * 0.5;
if (s < v) {
v -= s;
y = ny;
lx = nlx;
rx = nrx;
if (imag(plg[lt]) == ny) {
--lt;
}
if (imag(plg[rt]) == ny) {
++rt;
}
assert(lt >= rt);
} else {
D ret = y;
D a = (w2 - w1) / h * 0.5;
D b = w1;
D c = -v;
if (abs(a) > EPS) {
D d = b * b - 4 * a * c;
assert(d >= 0);
d = sqrt(d);
D t1 = (-b + d) / a * 0.5;
D t2 = (-b - d) / a * 0.5;
if (t1 > t2) {
swap(t1, t2);
}
assert(t2 >= 0);
if (t1 >= 0) {
ret += t1;
} else {
ret += t2;
}
} else {
D t = -c / b;
assert(t >= 0);
ret += t;
}
return ret;
}
}
}
int main() {
cout << fixed << setprecision(9);
ios::sync_with_stdio(false);
int n;
D d, v;
while (cin >> n >> d >> v, n) {
v /= d;
vector<P> pt(n), plg(n);
for (int i = 0; i < n; ++i) {
D x, y;
cin >> x >> y;
pt[i] = P(x, y);
}
D ans = -1;
for (int i = 0; i < n; ++i) {
P rot = polar(D(1), -arg(pt[(i + 1) % n] - pt[i]));
for (int j = 0; j < n; ++j) {
plg[j] = (pt[(i + j) % n] - pt[i]) * rot;
}
D t = calc(plg, v);
ans = max(ans, t);
}
cout << ans << '\n';
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 18], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 20]]
| 1
| 676
| 2
|
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
while (cin >> n >> m, n || m) {
vector<ll> k(n);
for (int i = 0; i < n; ++i) {
cin >> k[i];
k[i] %= m;
}
vector<ll> sum(n + 1);
for (int i = 0; i < n; ++i) {
sum[i + 1] = (sum[i] + k[i]) % m;
}
ll ans = 0;
set<ll> s;
s.insert(0);
for (int i = 1; i <= n; ++i) {
auto it = s.lower_bound(sum[i] + 1);
if (it != s.end()) {
ans = max(ans, (sum[i] + (*it)) % m);
} else {
ans = max(ans, sum[i]);
}
s.insert(sum[i]);
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
while (cin >> n >> m, n || m) {
vector<ll> k(n);
for (int i = 0; i < n; ++i) {
cin >> k[i];
k[i] %= m;
}
vector<ll> sum(n + 1);
for (int i = 0; i < n; ++i) {
sum[i + 1] = (sum[i] + k[i]) % m;
}
ll ans = 0;
set<ll> s;
s.insert(0);
for (int i = 1; i <= n; ++i) {
auto it = s.lower_bound(sum[i] + 1);
if (it != s.end()) {
ans = max(ans, (sum[i] - (*it) + m) % m);
} else {
ans = max(ans, sum[i]);
}
s.insert(sum[i]);
}
cout << ans << endl;
}
}
|
[["-", 3, 4, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 3, 4, 0, 16, 31, 23, 0, 16, 12, 22]]
| 1
| 242
| 4
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
struct SegNode {
int v;
SegNode(int v) : v(v) {}
SegNode operator*(const SegNode &r) const { return (v > r.v ? *this : r); }
} e(-(1 << 30));
struct SegmentTree {
int sz;
vector<SegNode> seg;
SegmentTree(int n) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz - 1, e);
}
void update(int k, const SegNode &x) {
k += sz - 1;
seg[k] = x;
while (k > 0) {
k = (k - 1) >> 1;
seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
}
}
SegNode query(int a, int b, int k, int l, int r) {
if (a >= r || b <= l)
return (e);
if (a <= l && r <= b)
return (seg[k]);
return (query(a, b, 2 * k + 1, l, (l + r) >> 1) *
query(a, b, 2 * k + 2, (l + r) >> 1, r));
}
SegNode query(int a, int b) { return (query(a, b, 0, 0, sz)); }
};
int main() {
int N, M, X[30000];
while (cin >> N >> M, N) {
for (int i = 0; i < N; i++) {
cin >> X[i];
X[i] %= M;
}
vector<int> first(M, INF), last(2 * M, -INF);
first[0] = -1;
int sum = 0;
for (int i = 0; i < N; i++) {
sum += X[i];
sum %= M;
first[sum] = min(first[sum], i);
last[sum] = max(last[sum], i);
last[M + sum] = max(last[M + sum], i);
}
int ret = 0;
SegmentTree seg(N);
int ptr = 0;
for (int i = 0; i < M; i++) {
while (ptr - i < M) {
if (last[ptr] >= 0) {
seg.update(last[ptr], ptr);
}
++ptr;
}
ret = max(ret, seg.query(first[i] + 1, M).v - i);
}
cout << ret << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
struct SegNode {
int v;
SegNode(int v) : v(v) {}
SegNode operator*(const SegNode &r) const { return (v > r.v ? *this : r); }
} e(-(1 << 30));
struct SegmentTree {
int sz;
vector<SegNode> seg;
SegmentTree(int n) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz - 1, e);
}
void update(int k, const SegNode &x) {
k += sz - 1;
seg[k] = x;
while (k > 0) {
k = (k - 1) >> 1;
seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
}
}
SegNode query(int a, int b, int k, int l, int r) {
if (a >= r || b <= l)
return (e);
if (a <= l && r <= b)
return (seg[k]);
return (query(a, b, 2 * k + 1, l, (l + r) >> 1) *
query(a, b, 2 * k + 2, (l + r) >> 1, r));
}
SegNode query(int a, int b) { return (query(a, b, 0, 0, sz)); }
};
int main() {
int N, M, X[30000];
while (cin >> N >> M, N) {
for (int i = 0; i < N; i++) {
cin >> X[i];
X[i] %= M;
}
vector<int> first(M, INF), last(2 * M, -INF);
first[0] = -1;
int sum = 0;
for (int i = 0; i < N; i++) {
sum += X[i];
sum %= M;
first[sum] = min(first[sum], i);
last[sum] = max(last[sum], i);
last[M + sum] = max(last[M + sum], i);
}
int ret = 0;
SegmentTree seg(N);
int ptr = 0;
for (int i = 0; i < M; i++) {
while (ptr - i < M) {
if (last[ptr] >= 0) {
seg.update(last[ptr], ptr);
}
++ptr;
}
ret = max(ret, seg.query(first[i] + 1, N).v - i);
}
cout << ret << endl;
}
}
|
[["-", 0, 16, 31, 118, 28, 2, 3, 4, 0, 22], ["+", 0, 16, 31, 118, 28, 2, 3, 4, 0, 22]]
| 1
| 579
| 2
|
#include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, NAME, ...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__, pr5, pr4, pr3, pr2, pr1)(__VA_ARGS__)
#define pr1(a) (#a) << "=" << (a)
#define pr2(a, b) pr1(a) << ", " << pr1(b)
#define pr3(a, b, c) pr2(a, b) << ", " << pr1(c)
#define pr4(a, b, c, d) pr3(a, b, c) << ", " << pr1(d)
#define pr5(a, b, c, d, e) pr4(a, b, c, d) << ", " << pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL << 55;
const int mod = (1e9) + 7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int, int> P;
typedef long long ll;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
ostream &operator<<(ostream &o, P p) {
return o << "(" << p.first << "," << p.second << ")";
}
istream &operator>>(istream &i, P &p) { return i >> p.first >> p.second; }
ostream &operator<<(ostream &o, vector<auto> &a) {
int i = 0;
for (auto t : a)
o << (i++ ? " " : "") << t;
return o;
}
istream &operator>>(istream &i, vector<auto> &a) {
for (auto &t : a)
i >> t;
return i;
}
void prArr(auto a, string s = " ") {
int i = 0;
for (auto t : a)
cout << (i++ ? s : "") << t;
cout << endl;
}
signed main() {
while (1) {
int n, mod;
cin >> n >> mod;
if (n == 0 && mod == 0)
break;
vector<int> A(n);
cin >> A;
multiset<int> S;
vector<int> Mod(n);
for (int i = 0, s = 0; i < n; i++) {
s += A[i];
S.insert(s % mod);
S.insert(s % mod + mod);
Mod[i] = s % mod;
}
int ans = 0;
int ofset = 0;
for (int i = 0; i < n; i++) {
int num = *(--S.upper_bound(ofset + mod - 1));
Max(ans, num - ofset);
S.erase(S.find(Mod[i]));
S.erase(S.find(Mod[i] + mod));
ofset += A[i] % mod;
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, NAME, ...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__, pr5, pr4, pr3, pr2, pr1)(__VA_ARGS__)
#define pr1(a) (#a) << "=" << (a)
#define pr2(a, b) pr1(a) << ", " << pr1(b)
#define pr3(a, b, c) pr2(a, b) << ", " << pr1(c)
#define pr4(a, b, c, d) pr3(a, b, c) << ", " << pr1(d)
#define pr5(a, b, c, d, e) pr4(a, b, c, d) << ", " << pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL << 55;
const int mod = (1e9) + 7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int, int> P;
typedef long long ll;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
ostream &operator<<(ostream &o, P p) {
return o << "(" << p.first << "," << p.second << ")";
}
istream &operator>>(istream &i, P &p) { return i >> p.first >> p.second; }
ostream &operator<<(ostream &o, vector<auto> &a) {
int i = 0;
for (auto t : a)
o << (i++ ? " " : "") << t;
return o;
}
istream &operator>>(istream &i, vector<auto> &a) {
for (auto &t : a)
i >> t;
return i;
}
void prArr(auto a, string s = " ") {
int i = 0;
for (auto t : a)
cout << (i++ ? s : "") << t;
cout << endl;
}
signed main() {
while (1) {
int n, mod;
cin >> n >> mod;
if (n == 0 && mod == 0)
break;
vector<int> A(n);
cin >> A;
multiset<int> S;
vector<int> Mod(n);
for (int i = 0, s = 0; i < n; i++) {
s += A[i];
S.insert(s % mod);
S.insert(s % mod + mod);
Mod[i] = s % mod;
}
int ans = 0;
int ofset = 0;
for (int i = 0; i < n; i++) {
int num = *(--S.upper_bound(ofset + mod - 1));
Max(ans, num - ofset);
S.erase(S.find(Mod[i]));
S.erase(S.find(Mod[i] + mod));
ofset = (ofset + A[i]) % mod;
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
| 1
| 607
| 6
|
s;
main(t) {
for (; gets(&t); s += atoi())
;
s = !printf("%d\n", s);
}
|
s;
main(t) {
for (; gets(&t); s += atoi(&t))
;
s = !printf("%d\n", s);
} //////////
|
[["+", 26, 11, 12, 2, 3, 4, 0, 66, 17, 67], ["+", 26, 11, 12, 2, 3, 4, 0, 66, 28, 22]]
| 0
| 37
| 2
|
#include <stdio.h>
int main(void) {
int a = 0;
int i;
for (i = 0; i < 10; i++) {
int b;
scanf("%d", &b);
a += b;
}
printf("%d\n", a / 10);
return 0;
}
|
#include <stdio.h>
int main(void) {
int a = 0;
int i;
for (i = 0; i < 10; i++) {
int b;
scanf("%d", &b);
a += b;
}
printf("%d\n", a);
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 85], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 64
| 2
|
#include <stdio.h>
int main(void) {
int a[10], g = 0, i;
for (i = 0; i < 10; i++) {
scanf("%d", a[i]);
g = g + a[i];
}
printf("%d\n", g);
return 0;
}
|
#include <stdio.h>
int main(void) {
int a[10], g = 0, i;
for (i = 0; i < 10; i++) {
scanf("%d", &a[i]);
g += a[i];
}
printf("%d\n", g);
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 107]]
| 0
| 70
| 5
|
#include <stdio.h>
int main(void) {
int a, b, i;
a = 0;
b = 0;
for (i = 0; i < 10; i++) {
scanf("%d", &a);
a += b;
}
printf("%d\n", b);
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, i;
a = 0;
b = 0;
for (i = 0; i < 10; i++) {
scanf("%d", &a);
b = a + b;
}
printf("%d\n", b);
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
| 0
| 66
| 4
|
#include <cstdio>
int ans, n;
int main() {
for (int i = 0; i < 10; i++) {
scanf("%d", &n);
ans += n;
}
printf("%d\n", &ans);
}
|
#include <cstdio>
int ans, n;
int main() {
for (int i = 0; i < 10; i++) {
scanf("%d", &n);
ans += n;
}
printf("%d\n", ans);
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
| 1
| 54
| 1
|
### main
while true
n = gets.strip.to_i
break if n == 0
words = []
hists = {}
n.times do
ws = gets.strip.split(' ')
for w in ws
if hists[w].nil?
words << w
hists[w] = 1
else
hists[w] += 1
end
end
end
#p words
#p hists
k = gets.strip
kwords = words.select{|w| w[0] == k}.sort{|a, b|
(cmp = hists[b] <=> hists[b]) != 0 ? cmp : a <=> b
}[0, 5]
#p kwords
puts(kwords.empty? ? 'NA' : kwords.join(' '))
end
|
### main
while true
n = gets.strip.to_i
break if n == 0
words = []
hists = {}
n.times do
ws = gets.strip.split(' ')
for w in ws
if hists[w].nil?
words << w
hists[w] = 1
else
hists[w] += 1
end
end
end
#p words
#p hists
k = gets.strip
kwords = words.select{|w| w[0] == k}.sort{|a, b|
(cmp = hists[b] <=> hists[a]) != 0 ? cmp : a <=> b
}[0, 5]
#p kwords
puts(kwords.empty? ? 'NA' : kwords.join(' '))
end
|
[["-", 31, 739, 0, 662, 12, 738, 12, 742, 0, 22], ["+", 31, 739, 0, 662, 12, 738, 12, 742, 0, 22]]
| 4
| 148
| 2
|
#include <iostream>
#include <queue>
using namespace std;
struct grid {
char g[12][12];
int cost;
};
void paint(grid gr, char l_u_cell, char changecolor, int p_x, int p_y) {
if (gr.g[p_y][p_x] != l_u_cell) {
return;
}
gr.g[p_y][p_x] = changecolor;
paint(gr, l_u_cell, changecolor, p_x + 1, p_y);
paint(gr, l_u_cell, changecolor, p_x - 1, p_y);
paint(gr, l_u_cell, changecolor, p_x, p_y + 1);
paint(gr, l_u_cell, changecolor, p_x, p_y - 1);
}
bool chacker(grid gr, char l_u_cell, int X, int Y) {
bool flag = true;
for (int i = 1; i <= Y; i++) {
for (int j = 1; j <= X; j++) {
if (l_u_cell != gr.g[i][j]) {
flag = false;
break;
}
}
}
return flag;
}
int main() {
while (1) {
int X, Y;
cin >> X >> Y;
if (X == 0 && Y == 0)
break;
grid first;
for (int i = 1; i <= Y; i++) {
for (int j = 1; j <= X; j++) {
cin >> first.g[i][j];
}
}
first.cost = 0;
queue<grid> que;
que.push(first);
while (1) {
grid Grid = que.front();
que.pop();
char l_u_cell;
l_u_cell = Grid.g[1][1];
if (chacker(Grid, l_u_cell, X, Y)) {
cout << Grid.cost << endl;
break;
}
if (l_u_cell != 'R') {
grid tmp = Grid;
tmp.cost = tmp.cost + 1;
paint(tmp, l_u_cell, 'R', 1, 1);
que.push(tmp);
}
if (l_u_cell != 'G') {
grid tmp = Grid;
tmp.cost = tmp.cost + 1;
paint(tmp, l_u_cell, 'G', 1, 1);
que.push(tmp);
}
if (l_u_cell != 'B') {
grid tmp = Grid;
tmp.cost = tmp.cost + 1;
paint(tmp, l_u_cell, 'B', 1, 1);
que.push(tmp);
}
}
}
return 0;
}
|
#include <iostream>
#include <queue>
using namespace std;
struct grid {
char g[12][12];
int cost;
};
void paint(grid &gr, char l_u_cell, char changecolor, int p_x, int p_y) {
if (gr.g[p_y][p_x] != l_u_cell) {
return;
}
gr.g[p_y][p_x] = changecolor;
paint(gr, l_u_cell, changecolor, p_x + 1, p_y);
paint(gr, l_u_cell, changecolor, p_x - 1, p_y);
paint(gr, l_u_cell, changecolor, p_x, p_y + 1);
paint(gr, l_u_cell, changecolor, p_x, p_y - 1);
}
bool chacker(grid &gr, char l_u_cell, int X, int Y) {
bool flag = true;
for (int i = 1; i <= Y; i++) {
for (int j = 1; j <= X; j++) {
if (l_u_cell != gr.g[i][j]) {
flag = false;
break;
}
}
}
return flag;
}
int main() {
while (1) {
int X, Y;
cin >> X >> Y;
if (X == 0 && Y == 0)
break;
grid first;
for (int i = 1; i <= Y; i++) {
for (int j = 1; j <= X; j++) {
cin >> first.g[i][j];
}
}
first.cost = 0;
queue<grid> que;
que.push(first);
while (1) {
grid Grid = que.front();
que.pop();
char l_u_cell;
l_u_cell = Grid.g[1][1];
if (chacker(Grid, l_u_cell, X, Y)) {
cout << Grid.cost << endl;
break;
}
if (l_u_cell != 'R') {
grid tmp = Grid;
tmp.cost = tmp.cost + 1;
paint(tmp, l_u_cell, 'R', 1, 1);
que.push(tmp);
}
if (l_u_cell != 'G') {
grid tmp = Grid;
tmp.cost = tmp.cost + 1;
paint(tmp, l_u_cell, 'G', 1, 1);
que.push(tmp);
}
if (l_u_cell != 'B') {
grid tmp = Grid;
tmp.cost = tmp.cost + 1;
paint(tmp, l_u_cell, 'B', 1, 1);
que.push(tmp);
}
}
}
return 0;
}
|
[["+", 49, 53, 54, 55, 0, 56, 49, 352, 0, 67]]
| 1
| 520
| 2
|
#include <stdio.h>
int main() {
int n, m, i, j, k, l, mi, min, a, b, e;
int c[2][110] = {0};
while (scanf("%d %d", &n, &m), n || m) {
int d[110][110] = {0};
while (m--) {
scanf("%d %d %d", &a, &b, &e);
d[a][b] = d[b][a] = e;
}
for (i = 2; i <= n; i++)
c[0][i] = c[1][i] = 100000000;
c[0][1] = c[1][1] = 0;
for (k = 0; k < 2; k++) {
mi = 1;
int f[110] = {0};
for (i = 0; i < n * 2; i++) {
f[mi] = 1;
for (j = 1; j <= n; j++) {
if (d[mi][j] == 0)
continue;
if (c[k][j] > c[k][mi] + d[mi][j])
c[k][j] = c[k][mi] + d[mi][j];
if (k)
continue;
for (l = 1; l <= n; l++) {
if (d[j][l] == 0)
continue;
if (c[1][l] > c[0][mi])
c[1][l] = c[0][mi];
}
}
min = 2100000000;
for (j = 1; j <= n; j++) {
if (f[j])
continue;
if (min > c[l][j])
min = c[k][mi = j];
}
}
// for(j=1;j<=n;j++)printf("%d ",c[k][j]);printf("\n");
}
printf("%d\n", c[1][n]);
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, m, i, j, k, l, mi, min, a, b, e;
int c[2][110] = {0};
while (scanf("%d %d", &n, &m), n || m) {
int d[110][110] = {0};
while (m--) {
scanf("%d %d %d", &a, &b, &e);
d[a][b] = d[b][a] = e;
}
for (i = 2; i <= n; i++)
c[0][i] = c[1][i] = 100000000;
c[0][1] = c[1][1] = 0;
for (k = 0; k < 2; k++) {
mi = 1;
int f[110] = {0};
for (i = 0; i < n * 2; i++) {
f[mi] = 1;
for (j = 1; j <= n; j++) {
if (d[mi][j] == 0)
continue;
if (c[k][j] > c[k][mi] + d[mi][j])
c[k][j] = c[k][mi] + d[mi][j];
if (k)
continue;
for (l = 1; l <= n; l++) {
if (d[j][l] == 0)
continue;
if (c[1][l] > c[0][mi])
c[1][l] = c[0][mi];
}
}
min = 2100000000;
for (j = 1; j <= n; j++) {
if (f[j])
continue;
if (min > c[k][j])
min = c[k][mi = j];
}
}
// for(j=1;j<=n;j++)printf("%d ",c[k][j]);printf("\n");
}
printf("%d\n", c[1][n]);
}
return 0;
}
|
[["-", 15, 23, 0, 16, 12, 69, 28, 69, 71, 22], ["+", 15, 23, 0, 16, 12, 69, 28, 69, 71, 22]]
| 0
| 441
| 2
|
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#include <cstdio>
#include <queue>
#include <set>
using namespace std;
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
int main() {
while (true) {
const int n = getInt();
const int m = getInt();
if (n + m == 0)
break;
const int MAX = 100000;
vector<vector<int>> g(n, vector<int>(n, MAX));
vector<vector<int>> dp(n, vector<int>(3, -1));
REP(i, m) {
const int a = getInt() - 1;
const int b = getInt() - 1;
const int c = getInt();
g[a][b] = min(g[a][b], c);
g[b][a] = min(g[b][a], c);
}
typedef pair<int, pair<int, int>> data;
priority_queue<data, vector<data>, greater<data>> pq;
pq.push(make_pair(0, make_pair(0, 0)));
while (pq.size()) {
const data d = pq.top();
pq.pop();
const int cost = d.first;
const int pos = d.second.first;
const int cnt = d.second.second;
if (cnt != 1 && pos == n - 1) {
printf("%d\n", cost);
break;
}
if (dp[pos][cnt] != -1)
continue;
dp[pos][cnt] = cost;
REP(i, n) if (g[pos][i] != MAX) {
if (cnt == 1) {
if (dp[i][cnt] == -1) {
pq.push(make_pair(cost, make_pair(i, 2)));
}
} else {
if (cnt == 0) {
if (dp[i][1] == -1) {
pq.push(make_pair(cost, make_pair(i, 1)));
}
}
if (dp[i][cnt] == -1) {
pq.push(make_pair(cost + g[pos][i], make_pair(i, cnt)));
}
}
}
}
}
return 0;
}
|
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#include <cstdio>
#include <queue>
#include <set>
using namespace std;
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
int main() {
while (true) {
const int n = getInt();
const int m = getInt();
if (n + m == 0)
break;
const int MAX = 100000;
vector<vector<int>> g(n, vector<int>(n, MAX));
vector<vector<int>> dp(n, vector<int>(3, -1));
REP(i, m) {
const int a = getInt() - 1;
const int b = getInt() - 1;
const int c = getInt();
g[a][b] = min(g[a][b], c);
g[b][a] = min(g[b][a], c);
}
typedef pair<int, pair<int, int>> data;
priority_queue<data, vector<data>, greater<data>> pq;
pq.push(make_pair(0, make_pair(0, 0)));
while (pq.size()) {
const data d = pq.top();
pq.pop();
const int cost = d.first;
const int pos = d.second.first;
const int cnt = d.second.second;
if (cnt != 1 && pos == n - 1) {
printf("%d\n", cost);
break;
}
if (dp[pos][cnt] != -1)
continue;
dp[pos][cnt] = cost;
REP(i, n) if (g[pos][i] != MAX) {
if (cnt == 1) {
if (dp[i][2] == -1) {
pq.push(make_pair(cost, make_pair(i, 2)));
}
} else {
if (cnt == 0) {
if (dp[i][1] == -1) {
pq.push(make_pair(cost, make_pair(i, 1)));
}
}
if (dp[i][cnt] == -1) {
pq.push(make_pair(cost + g[pos][i], make_pair(i, cnt)));
}
}
}
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13]]
| 1
| 502
| 2
|
#include <stdio.h>
#include <string.h>
#define MAX(x, y) ((x > y) ? x : y)
typedef struct g {
int d, s, e;
} G;
G a[12];
typedef struct p {
int x, y, z, f;
} P;
P q[50000], sq[50000], cp;
int qn, sqn;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char map[25][25];
int func(int d, P p) {
p.x += dx[d];
p.y += dy[d];
int m = map[p.y][p.x] - '0';
if (0 <= m && m <= 9 && !(p.f & (1 << m)))
return m;
else
return -1;
}
void func2(int f) {
int i;
for (i = 0; i < 10; i++) {
if ((f >> i) & 1)
printf("1");
else
printf("0");
}
printf("\n");
}
int main() {
int i, j, k, w, h, n, m, mt, t, ans;
char s;
while (1) {
scanf("%d %d\n", &w, &h);
if (w + h == 0)
break;
for (i = 0; i <= h + 1; i++)
map[i][0] = map[i][w + 1] = '#';
for (i = 1; i <= w; i++)
map[0][i] = map[h + 1][i] = '#';
for (i = 1; i <= h; i++) {
for (j = 1; j <= w; j++) {
scanf("%c ", &map[i][j]);
if (map[i][j] == 'P') {
q[0] = (P){j, i, 0, 0};
map[i][j] = '.';
}
}
}
// for(i=0;i<=h+1;i++)printf("%s\n",map[i]);
mt = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &m);
scanf("%d%d%d", &a[m].d, &a[m].s, &a[m].e);
mt = MAX(mt, a[m].e);
}
qn = 1;
t = 0;
for (i = 0; i < 4; i++) {
m = func(i, q[0]);
if (m != -1 && a[m].s <= 0 && 0 < a[m].e) {
q[0].z += a[m].d;
q[0].f = q[0].f | (1 << m);
}
}
while (t <= mt + 1) {
sqn = 0;
for (i = 0; i < qn; i++) {
// printf("%2d %2d %3d ",q[i].x,q[i].y,q[i].z);
// func2(q[i].f);
for (j = 0; j < 4; j++) {
cp = q[i];
cp.x += dx[j];
cp.y += dy[j];
if (map[cp.y][cp.x] == '.') {
for (k = 0; k < 4; k++) {
m = func(k, cp);
if (m != -1 && a[m].s <= t && t < a[m].e) {
cp.z += a[m].d;
cp.f = cp.f | (1 << m);
}
}
for (k = 0; k < sqn; k++) {
// if(sq[k].x==cp.x && sq[k].y==cp.y && (sq[k].z>cp.z ||
// sq[k].f==cp.f))break;
if (sq[k].x == cp.x && sq[k].y == cp.y) {
if (cp.f > sq[k].f && !((~cp.f) & sq[k].f)) {
sq[k] = cp;
break;
}
if (cp.f == sq[k].f)
break;
if (cp.f < sq[k].f && !(cp.f & (~sq[k].f)))
break;
}
}
if (k == sqn)
sq[sqn++] = cp;
}
}
}
memcpy(q, sq, sizeof(P) * sqn);
qn = sqn;
t++;
// printf("\n");
}
ans = 0;
// printf("%d\n",sqn);
for (i = 0; i < qn; i++)
ans = MAX(ans, q[i].z);
printf("%d\n", ans);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define MAX(x, y) ((x > y) ? x : y)
typedef struct g {
int d, s, e;
} G;
G a[12];
typedef struct p {
int x, y, z, f;
} P;
P q[50000], sq[50000], cp;
int qn, sqn;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char map[25][25];
int func(int d, P p) {
p.x += dx[d];
p.y += dy[d];
int m = map[p.y][p.x] - '0';
if (0 <= m && m <= 9 && !(p.f & (1 << m)))
return m;
else
return -1;
}
void func2(int f) {
int i;
for (i = 0; i < 10; i++) {
if ((f >> i) & 1)
printf("1");
else
printf("0");
}
printf("\n");
}
int main() {
int i, j, k, w, h, n, m, mt, t, ans;
char s;
while (1) {
scanf("%d %d\n", &w, &h);
if (w + h == 0)
break;
for (i = 0; i <= h + 1; i++)
map[i][0] = map[i][w + 1] = '#';
for (i = 1; i <= w; i++)
map[0][i] = map[h + 1][i] = '#';
for (i = 1; i <= h; i++) {
for (j = 1; j <= w; j++) {
scanf("%c ", &map[i][j]);
if (map[i][j] == 'P') {
q[0] = (P){j, i, 0, 0};
map[i][j] = '.';
}
}
}
// for(i=0;i<=h+1;i++)printf("%s\n",map[i]);
mt = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &m);
scanf("%d%d%d", &a[m].d, &a[m].s, &a[m].e);
mt = MAX(mt, a[m].e);
}
qn = 1;
t = 1;
for (i = 0; i < 4; i++) {
m = func(i, q[0]);
if (m != -1 && a[m].s <= 0 && 0 < a[m].e) {
q[0].z += a[m].d;
q[0].f = q[0].f | (1 << m);
}
}
while (t <= mt + 1) {
sqn = 0;
for (i = 0; i < qn; i++) {
// printf("%2d %2d %3d ",q[i].x,q[i].y,q[i].z);
// func2(q[i].f);
for (j = 0; j < 4; j++) {
cp = q[i];
cp.x += dx[j];
cp.y += dy[j];
if (map[cp.y][cp.x] == '.') {
for (k = 0; k < 4; k++) {
m = func(k, cp);
if (m != -1 && a[m].s <= t && t < a[m].e) {
cp.z += a[m].d;
cp.f = cp.f | (1 << m);
}
}
for (k = 0; k < sqn; k++) {
// if(sq[k].x==cp.x && sq[k].y==cp.y && (sq[k].z>cp.z ||
// sq[k].f==cp.f))break;
if (sq[k].x == cp.x && sq[k].y == cp.y) {
if (cp.f > sq[k].f && !((~cp.f) & sq[k].f)) {
sq[k] = cp;
break;
}
if (cp.f == sq[k].f)
break;
if (cp.f < sq[k].f && !(cp.f & (~sq[k].f)))
break;
}
}
if (k == sqn)
sq[sqn++] = cp;
}
}
}
memcpy(q, sq, sizeof(P) * sqn);
qn = sqn;
t++;
// printf("\n");
}
ans = 0;
// printf("%d\n",sqn);
for (i = 0; i < qn; i++)
ans = MAX(ans, q[i].z);
printf("%d\n", ans);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
| 0
| 1,023
| 2
|
#include <bits/stdc++.h>
using namespace std;
int w, h, n;
char mas[20][20];
int change[10];
typedef pair<int, int> Pi;
typedef pair<Pi, Pi> Piii;
typedef pair<Piii, int> Piiii;
Pi p;
struct sell {
int d; //値引き額
int s; //開始時刻
int e; //終了時刻
};
sell shop[10];
int min_cost[20][20][1 << 10];
int bfs() {
priority_queue<Piiii, vector<Piiii>, greater<Piiii>>
que; // Pii( (買った商品, 今の時間), 座標)
const int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1};
memset(min_cost, -1, sizeof(min_cost));
que.push(Piiii(Piii(Pi(0, 0), p), 0));
min_cost[p.second][p.first][0] = 0;
int ret = 0;
while (!que.empty()) {
Piiii p = que.top();
que.pop();
Pi point = p.first.second;
int bit = p.first.first.second, time = p.first.first.first;
int cost = p.second;
for (int i = 0; i < 4; i++) {
int ny = point.second + dy[i], nx = point.first + dx[i];
if (ny < 0 || ny >= h || nx < 0 || nx >= w)
continue;
if (!isdigit(mas[ny][nx]))
continue;
int pos = change[mas[ny][nx] - '0'];
if (pos == -1)
continue;
if (shop[pos].s <= time && time < shop[pos].e && !((bit >> i) & 1)) {
bit |= (1 << i);
cost += shop[pos].d;
}
}
if (cost < min_cost[point.second][point.first][bit]) {
continue;
}
min_cost[point.second][point.first][bit] =
max(cost, min_cost[point.second][point.first][bit]);
if (ret < min_cost[point.second][point.first][bit]) {
ret = min_cost[point.second][point.first][bit];
}
for (int i = 0; i < 4; i++) {
int ny = point.second + dy[i], nx = point.first + dx[i];
if (ny < 0 || ny >= h || nx < 0 || nx >= w)
continue;
if (isdigit(mas[ny][nx])) {
int time_sell = change[mas[ny][nx] - '0'];
if (time_sell == -1)
continue;
if (!((bit >> time_sell) & 1)) {
sell se = shop[time_sell];
if (se.s > time) {
que.push(Piiii(Piii(Pi(se.s, bit), point), cost));
}
}
} else {
if (min_cost[point.second][point.first][bit] > min_cost[ny][nx][bit]) {
que.push(Piiii(Piii(Pi(time + 1, bit), Pi(nx, ny)), cost));
min_cost[ny][nx][bit] = min_cost[point.second][point.first][bit];
}
}
}
}
return ret;
}
int main() {
while (cin >> w >> h, w) {
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> mas[i][j];
if (mas[i][j] == 'P')
p = Pi(j, i);
}
}
cin >> n;
memset(change, -1, sizeof(change));
for (int i = 0; i < n; i++) {
int g;
cin >> g;
cin >> shop[i].d >> shop[i].s >> shop[i].e;
change[i] = g;
}
cout << bfs() << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int w, h, n;
char mas[20][20];
int change[10];
typedef pair<int, int> Pi;
typedef pair<Pi, Pi> Piii;
typedef pair<Piii, int> Piiii;
Pi p;
struct sell {
int d; //値引き額
int s; //開始時刻
int e; //終了時刻
};
sell shop[10];
int min_cost[20][20][1 << 10];
int bfs() {
priority_queue<Piiii, vector<Piiii>, greater<Piiii>>
que; // Pii( (買った商品, 今の時間), 座標)
const int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1};
memset(min_cost, -1, sizeof(min_cost));
que.push(Piiii(Piii(Pi(0, 0), p), 0));
min_cost[p.second][p.first][0] = 0;
int ret = 0;
while (!que.empty()) {
Piiii p = que.top();
que.pop();
Pi point = p.first.second;
int bit = p.first.first.second, time = p.first.first.first;
int cost = p.second;
for (int i = 0; i < 4; i++) {
int ny = point.second + dy[i], nx = point.first + dx[i];
if (ny < 0 || ny >= h || nx < 0 || nx >= w)
continue;
if (!isdigit(mas[ny][nx]))
continue;
int pos = change[mas[ny][nx] - '0'];
if (pos == -1)
continue;
if (shop[pos].s <= time && time < shop[pos].e && !((bit >> pos) & 1)) {
bit |= (1 << pos);
cost += shop[pos].d;
}
}
if (cost < min_cost[point.second][point.first][bit]) {
continue;
}
min_cost[point.second][point.first][bit] =
max(cost, min_cost[point.second][point.first][bit]);
if (ret < min_cost[point.second][point.first][bit]) {
ret = min_cost[point.second][point.first][bit];
}
for (int i = 0; i < 4; i++) {
int ny = point.second + dy[i], nx = point.first + dx[i];
if (ny < 0 || ny >= h || nx < 0 || nx >= w)
continue;
if (isdigit(mas[ny][nx])) {
int time_sell = change[mas[ny][nx] - '0'];
if (time_sell == -1)
continue;
if (!((bit >> time_sell) & 1)) {
sell se = shop[time_sell];
if (se.s > time) {
que.push(Piiii(Piii(Pi(se.s, bit), point), cost));
}
}
} else {
if (min_cost[point.second][point.first][bit] > min_cost[ny][nx][bit]) {
que.push(Piiii(Piii(Pi(time + 1, bit), Pi(nx, ny)), cost));
min_cost[ny][nx][bit] = min_cost[point.second][point.first][bit];
}
}
}
}
return ret;
}
int main() {
while (cin >> w >> h, w) {
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> mas[i][j];
if (mas[i][j] == 'P')
p = Pi(j, i);
}
}
cin >> n;
memset(change, -1, sizeof(change));
for (int i = 0; i < n; i++) {
int g;
cin >> g;
cin >> shop[i].d >> shop[i].s >> shop[i].e;
change[i] = g;
}
cout << bfs() << endl;
}
}
|
[["-", 28, 23, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 28, 23, 0, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 12, 22]]
| 1
| 922
| 4
|
#include <iostream>
using namespace std;
struct comd {
int sn, d, s, e;
};
int main() {
int x, y, i, j, k, g, n, t, a, b, e, h,
dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1}, d[2][20][20][256],
m[20][20], f[20][20];
char c;
comd co[10];
while (cin >> x >> y && x > 0) {
for (h = 0; h < 2; h++)
for (j = 0; j < 20; j++)
for (k = 0; k < 20; k++)
for (g = 0; g < 256; g++)
d[h][j][k][g] = -1;
for (i = 0; i < y; i++) {
for (j = 0; j < x; j++) {
cin >> c;
f[i][j] = 0;
if (c >= '0' && c <= '9')
m[i][j] = c - '0';
else
m[i][j] = -1;
if (c == 'P') {
f[i][j] = 1;
d[0][i][j][0] = 0;
}
}
}
cin >> n;
for (i = 0; i < n; i++) {
cin >> g;
cin >> co[g].d >> co[g].s >> co[g].e;
co[g].sn = (1 << i);
}
for (t = 0, h = 0; t < 100; t++) {
for (i = 0; i < y; i++)
for (j = 0; j < x; j++) {
if (f[i][j] == 0)
continue;
for (k = 0; k < 256; k++) {
if (d[h][i][j][k] == -1)
continue;
a = k;
b = d[h][i][j][k];
for (g = 0; g < 4; g++) {
if (j + dx[g] < 0 || j + dx[g] >= x || i + dy[g] < 0 ||
i + dy[g] >= y)
continue;
e = m[i + dy[g]][j + dx[g]];
if (e >= 0)
if ((co[e].sn & a) == 0 && co[e].s <= t && co[e].e > t) {
b += co[e].d;
a = a | co[e].sn;
}
}
d[h][i][j][a] = b;
for (g = 0; g < 4; g++)
if (j + dx[g] >= 0 && j + dx[g] < x && i + dy[g] >= 0 &&
i + dy[g] < y)
if (m[i + dy[g]][j + dx[g]] < 0) {
d[h][i + dy[g]][j + dx[g]][a] = b;
f[i + dy[g]][j + dx[g]] = 1;
}
}
}
h = 1 - h;
}
a = -1;
for (i = 0; i < y; i++)
for (j = 0; j < x; j++)
for (k = 0; k < 256; k++)
if (a < d[0][i][j][k])
a = d[0][i][j][k];
cout << a << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
struct comd {
int sn, d, s, e;
};
int main() {
int x, y, i, j, k, g, n, t, a, b, e, h,
dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1}, d[2][20][20][256],
m[20][20], f[20][20];
char c;
comd co[10];
while (cin >> x >> y && x > 0) {
for (h = 0; h < 2; h++)
for (j = 0; j < 20; j++)
for (k = 0; k < 20; k++)
for (g = 0; g < 256; g++)
d[h][j][k][g] = -1;
for (i = 0; i < y; i++) {
for (j = 0; j < x; j++) {
cin >> c;
f[i][j] = 0;
if (c >= '0' && c <= '9')
m[i][j] = c - '0';
else
m[i][j] = -1;
if (c == 'P') {
f[i][j] = 1;
d[0][i][j][0] = 0;
}
}
}
cin >> n;
for (i = 0; i < n; i++) {
cin >> g;
cin >> co[g].d >> co[g].s >> co[g].e;
co[g].sn = (1 << i);
}
for (t = 0, h = 0; t <= 100; t++) {
for (i = 0; i < y; i++)
for (j = 0; j < x; j++) {
if (f[i][j] == 0)
continue;
for (k = 0; k < 256; k++) {
if (d[h][i][j][k] == -1)
continue;
a = k;
b = d[h][i][j][k];
for (g = 0; g < 4; g++) {
if (j + dx[g] < 0 || j + dx[g] >= x || i + dy[g] < 0 ||
i + dy[g] >= y)
continue;
e = m[i + dy[g]][j + dx[g]];
if (e >= 0)
if ((co[e].sn & a) == 0 && co[e].s <= t && co[e].e > t) {
b += co[e].d;
a = a | co[e].sn;
}
}
d[h][i][j][a] = b;
for (g = 0; g < 4; g++)
if (j + dx[g] >= 0 && j + dx[g] < x && i + dy[g] >= 0 &&
i + dy[g] < y)
if (m[i + dy[g]][j + dx[g]] < 0) {
d[1 - h][i + dy[g]][j + dx[g]][a] = b;
f[i + dy[g]][j + dx[g]] = 1;
}
}
}
h = 1 - h;
}
a = -1;
for (i = 0; i < y; i++)
for (j = 0; j < x; j++)
for (k = 0; k < 256; k++)
if (a < d[0][i][j][k])
a = d[0][i][j][k];
cout << a << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 28, 69, 28, 69, 341, 342, 0, 16, 31, 13], ["+", 28, 69, 28, 69, 341, 342, 0, 16, 17, 33]]
| 1
| 861
| 4
|
// ynymxiaolongbao is a really pro!
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
struct Manju {
int k[10];
};
bool operator<(const Manju &m1, const Manju &m2) {
for (int i = 0; i < 10; i++) {
if (m1.k[i] < m2.k[i])
return true;
if (m1.k[i] > m2.k[i])
return false;
}
return false;
}
vector<Manju> dp[11][11], S; // dp[end][sum]
map<pair<int, Manju>, int> M;
void init() {
Manju MM;
for (int i = 0; i < 10; i++)
MM.k[i] = 0;
dp[0][0].push_back(MM);
for (int i = 0; i < 9; i++) {
for (int j = 0; j <= 10; j++) {
for (int k = 0; k < dp[i][j].size(); k++) {
for (int l = 0; l <= 10; l++) {
int SUM = j + l * (i + 1);
Manju P = dp[i][j][k];
if (SUM > 10)
continue;
P.k[i + 1] = l;
dp[i + 1][SUM].push_back(P);
}
}
}
}
S = dp[9][10];
}
int manju(int pos, Manju T) {
if (pos == S.size())
return 0;
if (M[make_pair(pos, T)] != 0)
return M[make_pair(pos, T)];
int maxn = 0, cnt = 0;
Manju U = T;
while (true) {
int maxn = max(maxn, manju(pos + 1, U) + cnt);
for (int i = 0; i < 10; i++) {
U.k[i] -= S[pos].k[i];
}
bool flag = true;
for (int i = 0; i < 10; i++) {
if (U.k[i] < 0)
flag = false;
}
if (flag == false)
break;
cnt++;
}
M[make_pair(pos, T)] = maxn;
return maxn;
}
int main() {
init();
int n;
while (true) {
cin >> n;
M.clear();
if (n == 0)
break;
Manju A;
for (int i = 0; i < 10; i++)
A.k[i] = 0;
int adv = 0;
for (int i = 0; i < n; i++) {
int W;
cin >> W;
if (W >= 1 && W <= 9)
A.k[W]++;
if (W == 10)
adv++;
}
for (int i = 1; i < 5; i++) {
int WW = min(A.k[10 - i], A.k[i]);
A.k[10 - i] -= WW;
A.k[i] -= WW;
adv += WW;
}
adv += A.k[5] / 2;
A.k[5] %= 2;
cout << manju(0, A) + adv << endl;
}
return 0;
}
|
// ynymxiaolongbao is a really pro!
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
struct Manju {
short k[10];
};
bool operator<(const Manju &m1, const Manju &m2) {
for (int i = 0; i < 10; i++) {
if (m1.k[i] < m2.k[i])
return true;
if (m1.k[i] > m2.k[i])
return false;
}
return false;
}
vector<Manju> dp[11][11], S; // dp[end][sum]
map<pair<int, Manju>, int> M;
void init() {
Manju MM;
for (int i = 0; i < 10; i++)
MM.k[i] = 0;
dp[0][0].push_back(MM);
for (int i = 0; i < 9; i++) {
for (int j = 0; j <= 10; j++) {
for (int k = 0; k < dp[i][j].size(); k++) {
for (int l = 0; l <= 10; l++) {
int SUM = j + l * (i + 1);
Manju P = dp[i][j][k];
if (SUM > 10)
continue;
P.k[i + 1] = l;
dp[i + 1][SUM].push_back(P);
}
}
}
}
S = dp[9][10];
}
int manju(int pos, Manju T) {
if (pos == S.size())
return 0;
if (M[make_pair(pos, T)] != 0)
return M[make_pair(pos, T)];
int maxn = 0, cnt = 0;
Manju U = T;
while (true) {
maxn = max(maxn, manju(pos + 1, U) + cnt);
for (int i = 0; i < 10; i++) {
U.k[i] -= S[pos].k[i];
}
bool flag = true;
for (int i = 0; i < 10; i++) {
if (U.k[i] < 0)
flag = false;
}
if (flag == false)
break;
cnt++;
}
M[make_pair(pos, T)] = maxn;
return maxn;
}
int main() {
init();
int n;
while (true) {
cin >> n;
M.clear();
if (n == 0)
break;
Manju A;
for (int i = 0; i < 10; i++)
A.k[i] = 0;
int adv = 0;
for (int i = 0; i < n; i++) {
int W;
cin >> W;
if (W >= 1 && W <= 9)
A.k[W]++;
if (W == 10)
adv++;
}
for (int i = 1; i < 5; i++) {
int WW = min(A.k[10 - i], A.k[i]);
A.k[10 - i] -= WW;
A.k[i] -= WW;
adv += WW;
}
adv += A.k[5] / 2;
A.k[5] %= 2;
cout << manju(0, A) + adv << endl;
}
return 0;
}
|
[["-", 0, 30, 0, 122, 8, 123, 0, 124, 39, 40], ["+", 0, 122, 8, 123, 0, 124, 39, 86, 0, 133], ["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40]]
| 1
| 716
| 3
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
bool check(const vector<vector<pair<int, int>>> &humans, int x, int y) {
for (int i = 0; i < 4; ++i) {
auto it = find(humans[i].begin(), humans[i].end(), make_pair(x, y));
if (it != humans[i].end())
return false;
}
return true;
}
int dx[] = {-1, 0, 1, 0, 0};
int dy[] = {0, 1, 0, -1, 0};
template <typename T> struct Compress {
map<T, int> mp;
map<int, T> revmp;
Compress(vector<T> vs) { setmp(vs); }
Compress() : mp(), revmp() {}
void setmp(vector<T> vs) {
sort(vs.begin(), vs.end());
vs.erase(unique(vs.begin(), vs.end()), vs.end());
for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
mp[vs[i]] = i;
revmp[i] = vs[i];
}
}
};
struct sale {
int id;
int d;
int s;
int e;
};
struct aa {
int flag;
int x;
int y;
int cost;
};
bool operator<(const vector<int> &l, const vector<int> &r) {
for (int i = 0; i < l.size(); ++i) {
if (l[i] < r[i])
return true;
else if (l[i] > r[i])
return false;
}
return false;
}
int solve(vector<int> haves, vector<int> nums) {
map<pair<vector<int>, int>, int> mp;
mp[make_pair(nums, 0)] = 1;
int ans = 1;
queue<pair<vector<int>, int>> que;
que.push(make_pair(nums, 0));
while (!que.empty()) {
auto atop(que.front());
que.pop();
int x = atop.second;
vector<int> v(atop.first);
int cost = mp[make_pair(atop.first, atop.second)];
ans = max(ans, cost);
for (int i = 0; i < haves.size(); ++i) {
if (v[i]) {
if (x + haves[i] >= 11) {
} else if (x + haves[i] == 10) {
v[i]--;
auto np = make_pair(v, 0);
if (mp[np] < cost + 1) {
mp[np] = cost + 1;
que.push(np);
}
v[i]++;
} else {
v[i]--;
auto np = make_pair(v, x + haves[i]);
if (mp[np] < cost) {
mp[np] = cost;
que.push(np);
}
v[i]++;
}
}
}
}
return ans - 1;
}
int main() {
while (true) {
int N;
cin >> N;
if (N == 0)
break;
vector<int> vs(10);
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
vs[a]++;
}
int ans = 0;
for (int i = 6; i <= 9; ++i) {
int x = min(vs[i], vs[10 - i]);
vs[i] -= x;
vs[10 - i] -= x;
ans += x;
}
{
int x = vs[5] / 2;
vs[5] -= x;
ans += x;
}
vector<int> haves;
vector<int> nums;
for (int i = 1; i <= 9; ++i) {
if (vs[i]) {
haves.push_back(i);
nums.push_back(vs[i]);
}
}
ans += solve(haves, nums);
cout << ans << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
bool check(const vector<vector<pair<int, int>>> &humans, int x, int y) {
for (int i = 0; i < 4; ++i) {
auto it = find(humans[i].begin(), humans[i].end(), make_pair(x, y));
if (it != humans[i].end())
return false;
}
return true;
}
int dx[] = {-1, 0, 1, 0, 0};
int dy[] = {0, 1, 0, -1, 0};
template <typename T> struct Compress {
map<T, int> mp;
map<int, T> revmp;
Compress(vector<T> vs) { setmp(vs); }
Compress() : mp(), revmp() {}
void setmp(vector<T> vs) {
sort(vs.begin(), vs.end());
vs.erase(unique(vs.begin(), vs.end()), vs.end());
for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
mp[vs[i]] = i;
revmp[i] = vs[i];
}
}
};
struct sale {
int id;
int d;
int s;
int e;
};
struct aa {
int flag;
int x;
int y;
int cost;
};
bool operator<(const vector<int> &l, const vector<int> &r) {
for (int i = 0; i < l.size(); ++i) {
if (l[i] < r[i])
return true;
else if (l[i] > r[i])
return false;
}
return false;
}
int solve(vector<int> haves, vector<int> nums) {
map<pair<vector<int>, int>, int> mp;
mp[make_pair(nums, 0)] = 1;
int ans = 1;
queue<pair<vector<int>, int>> que;
que.push(make_pair(nums, 0));
while (!que.empty()) {
auto atop(que.front());
que.pop();
int x = atop.second;
vector<int> v(atop.first);
int cost = mp[make_pair(atop.first, atop.second)];
ans = max(ans, cost);
for (int i = 0; i < haves.size(); ++i) {
if (v[i]) {
if (x + haves[i] >= 11) {
} else if (x + haves[i] == 10) {
v[i]--;
auto np = make_pair(v, 0);
if (mp[np] < cost + 1) {
mp[np] = cost + 1;
que.push(np);
}
v[i]++;
} else {
v[i]--;
auto np = make_pair(v, x + haves[i]);
if (mp[np] < cost) {
mp[np] = cost;
que.push(np);
}
v[i]++;
}
}
}
}
return ans - 1;
}
int main() {
while (true) {
int N;
cin >> N;
if (N == 0)
break;
vector<int> vs(10);
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
vs[a]++;
}
int ans = 0;
for (int i = 6; i <= 9; ++i) {
int x = min(vs[i], vs[10 - i]);
vs[i] -= x;
vs[10 - i] -= x;
ans += x;
}
{
int x = vs[5] / 2;
vs[5] -= 2 * x;
ans += x;
}
vector<int> haves;
vector<int> nums;
for (int i = 1; i <= 9; ++i) {
if (vs[i]) {
haves.push_back(i);
nums.push_back(vs[i]);
}
}
ans += solve(haves, nums);
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 17, 48]]
| 1
| 948
| 2
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int COUNTER_CLOCKWISE = +1;
const int CLOCKWISE = -1;
const int ONLINE_BACK = +2;
const int ONLINE_FRONT = -2;
const int ON_SEGMENT = 0;
const double EPS = 1e-6;
const double INF = 1e10;
const double PI = acos(-1);
typedef complex<double> Point;
typedef complex<double> Vector;
typedef vector<Point> Polygon;
struct Line {
Point a, b;
Line() {}
Line(const Point &_a, const Point &_b) {
a = _a;
b = _b;
}
};
// Line????????????
struct Segment {
Point a, b;
Segment() {}
Segment(const Point &_a, const Point &_b) {
a = _a;
b = _b;
}
};
struct Circle {
Point c;
double r;
Circle() {}
Circle(const Point &_c, const double &_r) {
c = _c;
r = _r;
}
};
istream &operator>>(istream &is, Point &p) {
double x, y;
is >> x >> y;
p.real(x);
p.imag(y);
return is;
}
Segment ToSegment(const Line l) { return Segment(l.a, l.b); }
Line ToLine(const Segment s) { return Line(s.a, s.b); }
//???????¨±???==
bool equals(const double &a, const double &b);
bool equals(const Vector &a, const Vector &b);
// Point?????????
bool comp(const Point &a, const Point &b);
//?§????????????????
double toRad(double a);
double toDeg(double a);
//?????¢??????
Point rotate(Point p, double d);
//??????
double dot(const Vector &a, const Vector &b);
//??????
double cross(const Vector &a, const Vector &b);
//????§???¢?????¢???
double GetArea(const Polygon &g);
//???????¨???????(O(1))
//?????¶:????????¨?????°??????
int CCW(const Point &p0, const Point &p1, const Point &p2);
//??´?????????(O(1))
bool IsOrthogonal(const Vector &a, const Vector &b);
bool IsOrthogonal(const Line &l1, const Line &l2);
//????????????(O(1))
bool IsParallel(const Vector &a, const Vector &b);
bool IsParallel(const Line &l1, const Line &l2);
//?°???±(O(1))
Point Project(const Line &s, const Point &p);
//????°?(O(1))
Point Reflect(const Line &s, const Point &p);
//?????¨??´???????????¢
double GetDistance(const Line &l, const Point &p);
//?????¨??????????????¢
double GetDistance(const Segment &s, const Point &p);
//????????¨??????????????¢
double GetDistance(const Segment &s1, const Segment &s2);
//??´?????¨?????????????????????(O(1))
bool Intersects(const Line &l, const Segment &s);
//??????????????????
bool Intersects(const Segment &l1, const Segment &l2);
//??´?????¨??´????????????(O(1))
Point GetIntersection(const Line &l1, const Line &l2);
//?????¨????????????
//?????????
// ???????????????????????°
vector<Point> GetIntersection(const Circle &c1, const Circle &c2);
//????§???¢????????????(O(n))
//?????????
// 0:???????????????
// 1:????????????
// 2:?????????
int Contains(const Polygon &g, const Point &p);
//??????(O(n))
//?????????
// x->y????????§???????°??????????????????????????¨???????
Polygon AndrewScan(Polygon &s);
//???????§???¢?????????(O(n))
Polygon ConvexCut(const Polygon &g, const Line &l);
//-----------------------------------------------------------
bool equals(const double &a, const double &b) { return abs(a - b) < EPS; }
bool equals(const Vector &a, const Vector &b) {
return equals(a.real(), b.real()) && equals(a.imag(), b.imag());
}
bool comp(const Point &a, const Point &b) {
return equals(a.real(), b.real()) ? a.imag() < b.imag() : a.real() < b.real();
}
double dot(const Vector &a, const Vector &b) {
return a.real() * b.real() + a.imag() * b.imag();
}
double cross(const Vector &a, const Vector &b) {
return a.real() * b.imag() - a.imag() * b.real();
}
double GetArea(const Polygon &g) {
if (g.size() < 3)
return 0;
double res = 0;
for (int i = 1; i < g.size() - 1; i++) {
res += cross(g[i] - g[0], g[i + 1] - g[0]);
}
return abs(res / 2);
}
int CCW(const Point &p0, const Point &p1, const Point &p2) {
Vector v1 = (Vector)(p1 - p0), v2 = p2 - p0;
if (cross(v1, v2) > EPS)
return COUNTER_CLOCKWISE;
if (cross(v1, v2) < -EPS)
return CLOCKWISE;
if (dot(v1, v2) < -EPS)
return ONLINE_BACK;
if (abs(v1) < abs(v2))
return ONLINE_FRONT;
return ON_SEGMENT;
}
bool IsOrthogonal(const Vector &a, const Vector &b) {
return equals(dot(a, b), 0.0);
}
bool IsOrthogonal(const Line &l1, const Line &l2) {
return equals(dot(l1.b - l1.a, l2.b - l2.a), 0.0);
}
bool IsParallel(const Vector &a, const Vector &b) {
return equals(cross(a, b), 0.0);
}
bool IsParallel(const Line &l1, const Line &l2) {
return equals(cross(l1.b - l1.a, l2.b - l2.a), 0.0);
}
Point Project(const Line &s, const Point &p) {
Vector v1 = s.b - s.a;
Vector v2 = p - s.a;
double r = dot(v1, v2) / norm(v1);
return s.a + v1 * r;
}
Point Reflect(const Line &s, const Point &p) {
return p + (Project(s, p) - p) * 2.0;
}
double GetDistance(const Line &l, const Point &p) {
return abs(cross(l.a - l.b, p - l.a) / abs(l.b - l.a));
}
double GetDistance(const Segment &s, const Point &p) {
if (dot(s.b - s.a, p - s.a) < 0.0)
return abs(p - s.a);
if (dot(s.a - s.b, p - s.b) < 0.0)
return abs(p - s.b);
return GetDistance(ToLine(s), p);
}
double GetDistance(const Segment &s1, const Segment &s2) {
if (Intersects(s1, s2))
return 0.0;
return min(min(GetDistance(s1, s2.a), GetDistance(s1, s2.b)),
min(GetDistance(s2, s1.a), GetDistance(s2, s1.b)));
}
bool Intersects(const Line &l, const Segment &s) {
return CCW(l.a, l.b, s.a) * CCW(l.a, l.b, s.b) != 1;
}
bool Intersects(const Segment &l1, const Segment &l2) {
return CCW(l1.a, l1.b, l2.a) * CCW(l1.a, l1.b, l2.b) <= 0 &&
CCW(l2.a, l2.b, l1.a) * CCW(l2.a, l2.b, l1.b) <= 0;
}
Point GetIntersection(const Line &l1, const Line &l2) {
Vector a1 = l1.b - l1.a, a2 = l2.b - l2.a;
Vector b1 = l2.a - l1.a, b2 = l1.a - l2.b;
double s1 = cross(a1, b1) / 2, s2 = cross(a1, b2) / 2;
return Point(l2.a.real() + a2.real() * s1 / (s1 + s2),
l2.a.imag() + a2.imag() * s1 / (s1 + s2));
}
vector<Point> GetIntersection(const Circle &c1, const Circle &c2) {
vector<Point> res;
double d, a, t;
d = sqrt(norm((c2.c - c1.c)));
if (d < abs(c1.r - c2.r) || c1.r + c2.r < d)
return res; //?????????0
a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
t = atan2(c2.c.imag() - c1.c.imag(), c2.c.real() - c1.c.real());
res.push_back(
Point(c1.c.real() + c1.r * cos(t + a), c1.c.imag() + c1.r * sin(t + a)));
res.push_back(
Point(c1.c.real() + c1.r * cos(t - a), c1.c.imag() + c1.r * sin(t - a)));
if (equals(res[0], res[1]))
res.pop_back(); //?????????1
return res;
}
int Contains(const Polygon &g, const Point &p) {
Line l = Line(p, Point(INF, p.imag()));
int cnt = 0, n = g.size();
for (int i = 0; i < n; i++) {
Vector a = g[i] - p;
Vector b = g[(i + 1) % n] - p;
if (CCW(g[i], g[(i + 1) % n], p) == 0)
return 2; //?????????
if (a.imag() > b.imag())
swap(a, b);
if (a.imag() <= EPS && EPS < b.imag() && cross(a, b) > EPS)
cnt++;
}
if ((cnt & 1) == 1)
return 1; //????????????
return 0; //???????????????
}
Polygon AndrewScan(Polygon &s) {
if (s.size() <= 2)
return s;
sort(s.begin(), s.end(), comp);
Polygon g;
for (int i = 0; i < s.size(); i++) {
// CCW?????¨?????????==COUNTER_CLOCKWISE???????????¨???????????????
for (int n = g.size(); n >= 2 && CCW(g[n - 2], g[n - 1], s[i]) != CLOCKWISE;
n--) {
g.pop_back();
}
g.push_back(s[i]);
}
for (int i = s.size() - 2; i >= 0; i--) {
for (int n = g.size(); CCW(g[n - 2], g[n - 1], s[i]) != CLOCKWISE; n--) {
g.pop_back();
}
g.push_back(s[i]);
}
reverse(g.begin(), g.end());
g.pop_back();
return g;
}
Polygon ConvexCut(const Polygon &g, const Line &l) {
Polygon res;
for (int i = 0; i < g.size(); i++) {
Segment s = Segment(g[i], g[(i + 1) % g.size()]);
if (CCW(l.a, l.b, s.a) != -1)
res.push_back(s.a);
if (CCW(l.a, l.b, s.a) * CCW(l.a, l.b, s.b) == -1)
res.push_back(GetIntersection(l, ToLine(s)));
}
return res;
}
// Latte
double toRad(double a) { return a / 180.0 * PI; }
double toDeg(double a) { return a * 180.0 / PI; }
Point rotate(Point p, double d) {
return Point(p.real() * cos(d) - p.imag() * sin(d),
p.real() * sin(d) + p.imag() * cos(d));
}
// Malta
struct UF {
int N;
vector<int> par, size;
void init(int _N) {
N = _N;
par.resize(N);
size.resize(N, 1);
for (int i = 0; i < N; i++)
par[i] = i;
}
int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (size[x] < size[y])
swap(x, y);
par[y] = x;
size[x] += size[y];
}
bool same(int x, int y) { return find(x) == find(y); }
};
#define rep(i, n) for (int i = 0; i < (n); i++)
int M;
vector<Polygon> vec;
bool isok(Polygon &g, Polygon &h) {
bool ret = false;
rep(i, 4) {
Segment s(g[i], g[(i + 1) % 4]);
rep(j, 4) {
Segment t(h[j], h[(j + 1) % 4]);
if (Intersects(s, t))
ret = true;
}
}
rep(i, 4) {
if (Contains(g, h[i]))
ret = true;
if (Contains(h, g[i]))
ret = true;
}
}
void solve() {
scanf("%d", &M);
vec.resize(M, Polygon(4));
rep(i, M) rep(j, 4) cin >> vec[i][j];
UF uf;
uf.init(M);
rep(i, M) rep(j, M) if (isok(vec[i], vec[j])) uf.unite(i, j);
int ans = 0;
rep(i, M) if (uf.find(i) == i) ans++;
printf("%d\n", ans);
}
signed main() {
int N;
while (scanf("%d", &N), N) {
rep(i, N) solve();
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int COUNTER_CLOCKWISE = +1;
const int CLOCKWISE = -1;
const int ONLINE_BACK = +2;
const int ONLINE_FRONT = -2;
const int ON_SEGMENT = 0;
const double EPS = 1e-6;
const double INF = 1e10;
const double PI = acos(-1);
typedef complex<double> Point;
typedef complex<double> Vector;
typedef vector<Point> Polygon;
struct Line {
Point a, b;
Line() {}
Line(const Point &_a, const Point &_b) {
a = _a;
b = _b;
}
};
// Line????????????
struct Segment {
Point a, b;
Segment() {}
Segment(const Point &_a, const Point &_b) {
a = _a;
b = _b;
}
};
struct Circle {
Point c;
double r;
Circle() {}
Circle(const Point &_c, const double &_r) {
c = _c;
r = _r;
}
};
istream &operator>>(istream &is, Point &p) {
double x, y;
is >> x >> y;
p.real(x);
p.imag(y);
return is;
}
Segment ToSegment(const Line l) { return Segment(l.a, l.b); }
Line ToLine(const Segment s) { return Line(s.a, s.b); }
//???????¨±???==
bool equals(const double &a, const double &b);
bool equals(const Vector &a, const Vector &b);
// Point?????????
bool comp(const Point &a, const Point &b);
//?§????????????????
double toRad(double a);
double toDeg(double a);
//?????¢??????
Point rotate(Point p, double d);
//??????
double dot(const Vector &a, const Vector &b);
//??????
double cross(const Vector &a, const Vector &b);
//????§???¢?????¢???
double GetArea(const Polygon &g);
//???????¨???????(O(1))
//?????¶:????????¨?????°??????
int CCW(const Point &p0, const Point &p1, const Point &p2);
//??´?????????(O(1))
bool IsOrthogonal(const Vector &a, const Vector &b);
bool IsOrthogonal(const Line &l1, const Line &l2);
//????????????(O(1))
bool IsParallel(const Vector &a, const Vector &b);
bool IsParallel(const Line &l1, const Line &l2);
//?°???±(O(1))
Point Project(const Line &s, const Point &p);
//????°?(O(1))
Point Reflect(const Line &s, const Point &p);
//?????¨??´???????????¢
double GetDistance(const Line &l, const Point &p);
//?????¨??????????????¢
double GetDistance(const Segment &s, const Point &p);
//????????¨??????????????¢
double GetDistance(const Segment &s1, const Segment &s2);
//??´?????¨?????????????????????(O(1))
bool Intersects(const Line &l, const Segment &s);
//??????????????????
bool Intersects(const Segment &l1, const Segment &l2);
//??´?????¨??´????????????(O(1))
Point GetIntersection(const Line &l1, const Line &l2);
//?????¨????????????
//?????????
// ???????????????????????°
vector<Point> GetIntersection(const Circle &c1, const Circle &c2);
//????§???¢????????????(O(n))
//?????????
// 0:???????????????
// 1:????????????
// 2:?????????
int Contains(const Polygon &g, const Point &p);
//??????(O(n))
//?????????
// x->y????????§???????°??????????????????????????¨???????
Polygon AndrewScan(Polygon &s);
//???????§???¢?????????(O(n))
Polygon ConvexCut(const Polygon &g, const Line &l);
//-----------------------------------------------------------
bool equals(const double &a, const double &b) { return abs(a - b) < EPS; }
bool equals(const Vector &a, const Vector &b) {
return equals(a.real(), b.real()) && equals(a.imag(), b.imag());
}
bool comp(const Point &a, const Point &b) {
return equals(a.real(), b.real()) ? a.imag() < b.imag() : a.real() < b.real();
}
double dot(const Vector &a, const Vector &b) {
return a.real() * b.real() + a.imag() * b.imag();
}
double cross(const Vector &a, const Vector &b) {
return a.real() * b.imag() - a.imag() * b.real();
}
double GetArea(const Polygon &g) {
if (g.size() < 3)
return 0;
double res = 0;
for (int i = 1; i < g.size() - 1; i++) {
res += cross(g[i] - g[0], g[i + 1] - g[0]);
}
return abs(res / 2);
}
int CCW(const Point &p0, const Point &p1, const Point &p2) {
Vector v1 = (Vector)(p1 - p0), v2 = p2 - p0;
if (cross(v1, v2) > EPS)
return COUNTER_CLOCKWISE;
if (cross(v1, v2) < -EPS)
return CLOCKWISE;
if (dot(v1, v2) < -EPS)
return ONLINE_BACK;
if (abs(v1) < abs(v2))
return ONLINE_FRONT;
return ON_SEGMENT;
}
bool IsOrthogonal(const Vector &a, const Vector &b) {
return equals(dot(a, b), 0.0);
}
bool IsOrthogonal(const Line &l1, const Line &l2) {
return equals(dot(l1.b - l1.a, l2.b - l2.a), 0.0);
}
bool IsParallel(const Vector &a, const Vector &b) {
return equals(cross(a, b), 0.0);
}
bool IsParallel(const Line &l1, const Line &l2) {
return equals(cross(l1.b - l1.a, l2.b - l2.a), 0.0);
}
Point Project(const Line &s, const Point &p) {
Vector v1 = s.b - s.a;
Vector v2 = p - s.a;
double r = dot(v1, v2) / norm(v1);
return s.a + v1 * r;
}
Point Reflect(const Line &s, const Point &p) {
return p + (Project(s, p) - p) * 2.0;
}
double GetDistance(const Line &l, const Point &p) {
return abs(cross(l.a - l.b, p - l.a) / abs(l.b - l.a));
}
double GetDistance(const Segment &s, const Point &p) {
if (dot(s.b - s.a, p - s.a) < 0.0)
return abs(p - s.a);
if (dot(s.a - s.b, p - s.b) < 0.0)
return abs(p - s.b);
return GetDistance(ToLine(s), p);
}
double GetDistance(const Segment &s1, const Segment &s2) {
if (Intersects(s1, s2))
return 0.0;
return min(min(GetDistance(s1, s2.a), GetDistance(s1, s2.b)),
min(GetDistance(s2, s1.a), GetDistance(s2, s1.b)));
}
bool Intersects(const Line &l, const Segment &s) {
return CCW(l.a, l.b, s.a) * CCW(l.a, l.b, s.b) != 1;
}
bool Intersects(const Segment &l1, const Segment &l2) {
return CCW(l1.a, l1.b, l2.a) * CCW(l1.a, l1.b, l2.b) <= 0 &&
CCW(l2.a, l2.b, l1.a) * CCW(l2.a, l2.b, l1.b) <= 0;
}
Point GetIntersection(const Line &l1, const Line &l2) {
Vector a1 = l1.b - l1.a, a2 = l2.b - l2.a;
Vector b1 = l2.a - l1.a, b2 = l1.a - l2.b;
double s1 = cross(a1, b1) / 2, s2 = cross(a1, b2) / 2;
return Point(l2.a.real() + a2.real() * s1 / (s1 + s2),
l2.a.imag() + a2.imag() * s1 / (s1 + s2));
}
vector<Point> GetIntersection(const Circle &c1, const Circle &c2) {
vector<Point> res;
double d, a, t;
d = sqrt(norm((c2.c - c1.c)));
if (d < abs(c1.r - c2.r) || c1.r + c2.r < d)
return res; //?????????0
a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
t = atan2(c2.c.imag() - c1.c.imag(), c2.c.real() - c1.c.real());
res.push_back(
Point(c1.c.real() + c1.r * cos(t + a), c1.c.imag() + c1.r * sin(t + a)));
res.push_back(
Point(c1.c.real() + c1.r * cos(t - a), c1.c.imag() + c1.r * sin(t - a)));
if (equals(res[0], res[1]))
res.pop_back(); //?????????1
return res;
}
int Contains(const Polygon &g, const Point &p) {
Line l = Line(p, Point(INF, p.imag()));
int cnt = 0, n = g.size();
for (int i = 0; i < n; i++) {
Vector a = g[i] - p;
Vector b = g[(i + 1) % n] - p;
if (CCW(g[i], g[(i + 1) % n], p) == 0)
return 2; //?????????
if (a.imag() > b.imag())
swap(a, b);
if (a.imag() <= EPS && EPS < b.imag() && cross(a, b) > EPS)
cnt++;
}
if ((cnt & 1) == 1)
return 1; //????????????
return 0; //???????????????
}
Polygon AndrewScan(Polygon &s) {
if (s.size() <= 2)
return s;
sort(s.begin(), s.end(), comp);
Polygon g;
for (int i = 0; i < s.size(); i++) {
// CCW?????¨?????????==COUNTER_CLOCKWISE???????????¨???????????????
for (int n = g.size(); n >= 2 && CCW(g[n - 2], g[n - 1], s[i]) != CLOCKWISE;
n--) {
g.pop_back();
}
g.push_back(s[i]);
}
for (int i = s.size() - 2; i >= 0; i--) {
for (int n = g.size(); CCW(g[n - 2], g[n - 1], s[i]) != CLOCKWISE; n--) {
g.pop_back();
}
g.push_back(s[i]);
}
reverse(g.begin(), g.end());
g.pop_back();
return g;
}
Polygon ConvexCut(const Polygon &g, const Line &l) {
Polygon res;
for (int i = 0; i < g.size(); i++) {
Segment s = Segment(g[i], g[(i + 1) % g.size()]);
if (CCW(l.a, l.b, s.a) != -1)
res.push_back(s.a);
if (CCW(l.a, l.b, s.a) * CCW(l.a, l.b, s.b) == -1)
res.push_back(GetIntersection(l, ToLine(s)));
}
return res;
}
// Latte
double toRad(double a) { return a / 180.0 * PI; }
double toDeg(double a) { return a * 180.0 / PI; }
Point rotate(Point p, double d) {
return Point(p.real() * cos(d) - p.imag() * sin(d),
p.real() * sin(d) + p.imag() * cos(d));
}
// Malta
struct UF {
int N;
vector<int> par, size;
void init(int _N) {
N = _N;
par.resize(N);
size.resize(N, 1);
for (int i = 0; i < N; i++)
par[i] = i;
}
int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (size[x] < size[y])
swap(x, y);
par[y] = x;
size[x] += size[y];
}
bool same(int x, int y) { return find(x) == find(y); }
};
#define rep(i, n) for (int i = 0; i < (n); i++)
int M;
vector<Polygon> vec;
bool isok(Polygon &g, Polygon &h) {
bool ret = false;
rep(i, 4) {
Segment s(g[i], g[(i + 1) % 4]);
rep(j, 4) {
Segment t(h[j], h[(j + 1) % 4]);
if (Intersects(s, t))
ret = true;
}
}
rep(i, 4) {
if (Contains(g, h[i]))
ret = true;
if (Contains(h, g[i]))
ret = true;
}
return ret;
}
void solve() {
scanf("%d", &M);
vec.resize(M, Polygon(4));
rep(i, M) rep(j, 4) cin >> vec[i][j];
UF uf;
uf.init(M);
rep(i, M) rep(j, M) if (isok(vec[i], vec[j])) uf.unite(i, j);
int ans = 0;
rep(i, M) if (uf.find(i) == i) ans++;
printf("%d\n", ans);
}
signed main() {
int N;
while (scanf("%d", &N), N) {
rep(i, N) solve();
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
| 1
| 3,158
| 3
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int best = 4280;
int k;
int n = 0;
int w = scan.nextInt();
while (w != -1) {
if (w > 30) {
n = 0;
n += 1150 + 125 * 10 + 140 * 10 + 160 * (w - 30);
} else if (w > 20 && w <= 30) {
n = 0;
n += 1150 + 125 * 10 + 140 * (w - 20);
} else if (w > 10 && w <= 20) {
n = 0;
n += 1150 + 120 * (w - 10);
} else if (w <= 10) {
n = 0;
n += 1150;
}
k = best - n;
System.out.println(k);
w = scan.nextInt();
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int best = 4280;
int k;
int n = 0;
int w = scan.nextInt();
while (w != -1) {
if (w > 30) {
n = 0;
n += 1150 + 125 * 10 + 140 * 10 + 160 * (w - 30);
} else if (w > 20 && w <= 30) {
n = 0;
n += 1150 + 125 * 10 + 140 * (w - 20);
} else if (w > 10 && w <= 20) {
n = 0;
n += 1150 + 125 * (w - 10);
} else if (w <= 10) {
n = 0;
n += 1150;
}
k = best - n;
System.out.println(k);
w = scan.nextInt();
}
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 31, 499], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 31, 499]]
| 3
| 200
| 2
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
while (w >= 0) {
int price = 1150;
if (w > 30) {
price *= 160 * (w - 30);
w = 30;
}
if (w > 20) {
price *= 140 * (w - 20);
w = 20;
}
if (w > 10) {
price *= 125 * (w - 10);
}
System.out.println(4280 - price);
w = sc.nextInt();
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
while (w >= 0) {
int price = 1150;
if (w > 30) {
price += 160 * (w - 30);
w = 30;
}
if (w > 20) {
price += 140 * (w - 20);
w = 20;
}
if (w > 10) {
price += 125 * (w - 10);
}
System.out.println(4280 - price);
w = sc.nextInt();
}
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 17, 108], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 17, 107]]
| 3
| 138
| 6
|
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
while (true) {
int w = in.nextInt();
if (w == -1)
break;
int S = 0;
if (w <= 10) {
S = 1150;
} else if (w <= 20) {
S = 1150 + (w % 10) * 125;
} else if (w <= 30) {
S = 1150 + 10 * 125 + (w % 20) * 140;
} else {
S = 1150 + 10 * 125 + 10 * 140 + (w % 30) * 160;
}
S = 4280 - S;
System.out.println(S);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
while (true) {
int w = in.nextInt();
if (w == -1)
break;
int S = 0;
if (w <= 10) {
S = 1150;
} else if (w <= 20) {
S = 1150 + (w - 10) * 125;
} else if (w <= 30) {
S = 1150 + 10 * 125 + (w - 20) * 140;
} else {
S = 1150 + 10 * 125 + 10 * 140 + (w - 30) * 160;
}
S = 4280 - S;
System.out.println(S);
}
}
}
|
[["-", 12, 16, 12, 16, 31, 23, 0, 16, 17, 109], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33]]
| 3
| 160
| 6
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int w = sc.nextInt();
if (w == -1)
break;
int pay = 0;
if (w < 10)
pay += 1150;
if (10 <= w && w < 20)
pay += 125 * (w - 10) + 1150;
if (20 <= w && w < 30)
pay += 140 * (w - 10) + 125 * 10 + 1150;
if (30 <= w)
pay += 160 * (w - 30) + 125 * 10 + 140 * 10 + 1150;
System.out.println(4280 - pay);
}
sc.close();
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int w = sc.nextInt();
if (w == -1)
break;
int pay = 0;
if (w < 10)
pay += 1150;
if (10 <= w && w < 20)
pay += 125 * (w - 10) + 1150;
if (20 <= w && w < 30)
pay += 140 * (w - 20) + 125 * 10 + 1150;
if (30 <= w)
pay += 160 * (w - 30) + 125 * 10 + 140 * 10 + 1150;
System.out.println(4280 - pay);
}
sc.close();
}
}
|
[["-", 31, 16, 31, 16, 12, 23, 0, 16, 12, 499], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 499]]
| 3
| 165
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws java.io.IOException {
Scanner scan = new Scanner(System.in);
int w = scan.nextInt();
int m = 4280;
while (w != -1) {
int r = 0;
if (w <= 10) {
r = 1150;
} else if (w <= 20) {
r = 1150 + (w - 10) * 152;
} else if (w <= 30) {
r = 1150 + 10 * 125 + (w - 20) * 140;
} else {
r = 1150 + 10 * 125 + 10 * 140 + (w - 30) * 160;
}
System.out.println(m - r);
w = scan.nextInt();
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws java.io.IOException {
Scanner scan = new Scanner(System.in);
int w = scan.nextInt();
int m = 4280;
while (w != -1) {
int r = 0;
if (w <= 10) {
r = 1150;
} else if (w <= 20) {
r = 1150 + (w - 10) * 125;
} else if (w <= 30) {
r = 1150 + 10 * 125 + (w - 20) * 140;
} else {
r = 1150 + 10 * 125 + 10 * 140 + (w - 30) * 160;
}
System.out.println(m - r);
w = scan.nextInt();
}
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 499], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 499]]
| 3
| 169
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String arg[]) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
if (n == -1)
return;
int uti = 1150;
int be = 4280;
int count = 11;
if (n > 10)
while (count <= 20 && count <= n) {
uti += 125;
count++;
}
if (n > 20)
while (count <= 30 && count <= n) {
uti += 140;
count++;
}
if (n > 30)
while (count <= 40 && count <= n) {
uti += 160;
count++;
}
System.out.println(be - uti);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String arg[]) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
if (n == -1)
return;
int uti = 1150;
int be = 4280;
int count = 11;
if (n > 10)
while (count <= 20 && count <= n) {
uti += 125;
count++;
}
if (n > 20)
while (count <= 30 && count <= n) {
uti += 140;
count++;
}
if (n > 30)
while (count <= n) {
uti += 160;
count++;
}
System.out.println(be - uti);
}
}
}
|
[["-", 64, 52, 15, 15, 0, 16, 31, 16, 12, 499], ["-", 0, 57, 64, 52, 15, 15, 0, 16, 17, 98], ["-", 64, 52, 15, 15, 0, 16, 12, 16, 31, 22], ["-", 64, 52, 15, 15, 0, 16, 12, 16, 17, 19]]
| 3
| 164
| 4
|
#include <stdio.h>
int main(void) {
int i, w, s, k = 0;
while (1) {
scanf("%d", &w);
if (w == -1)
break;
for (i = 11, k = 1150; i <= w; i++) {
if (i <= 20)
k += 140;
else if (i <= 30)
k += 140;
else
k += 1160;
}
printf("%d\n", 4280 - k);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int i, w, s, k = 0;
while (1) {
scanf("%d", &w);
if (w == -1)
break;
for (i = 11, k = 1150; i <= w; i++) {
if (i <= 20)
k += 125;
else if (i <= 30)
k += 140;
else
k += 160;
}
printf("%d\n", 4280 - k);
}
return (0);
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["-", 0, 57, 75, 76, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 12, 13]]
| 0
| 106
| 4
|
#include <stdio.h>
int main(void) {
int w;
while (scanf("%d", &w) + w != 0) {
int money = 1150;
if (w > 30) {
money += (w - 30) * 160;
w -= w % 30;
}
if (w > 20) {
money += (w - 20) * 140;
w -= w % 20;
}
if (w > 10) {
money += (w - 10) * 125;
}
printf("%d\n", 4280 - money);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int w;
while (scanf("%d", &w) + w != 0) {
int money = 1150;
if (w > 30) {
money += (w - 30) * 160;
w = 30;
}
if (w > 20) {
money += (w - 20) * 140;
w = 20;
}
if (w > 10) {
money += (w - 10) * 125;
}
printf("%d\n", 4280 - money);
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 110], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22]]
| 0
| 116
| 8
|
#// AOJ Volume2 0216
#include <stdio.h>
int fee(int w) {
int f;
int wt;
// 第1段階
f = 1150;
// 第2段階
w -= 10;
if (w <= 0) {
return (f);
}
if (w > 10) {
wt = 10;
} else {
wt = w;
}
f += wt * 125;
// 第3段階
w -= 10;
if (w <= 0) {
return (f);
}
if (w > 10) {
wt = 10;
} else {
wt = w;
}
f += wt * 140;
// 第4段階
w -= 10;
if (w <= 0) {
return (f);
}
f += w * 160;
return (f);
}
int main(void) {
int w;
while (1) {
scanf("%d", &w);
if (w == -1) {
break;
}
printf("%d\n", fee(w) - 4280);
}
return (0);
}
|
#// AOJ Volume2 0216
#include <stdio.h>
int fee(int w) {
int f;
int wt;
// 第1段階
f = 1150;
// 第2段階
w -= 10;
if (w <= 0) {
return (f);
}
if (w > 10) {
wt = 10;
} else {
wt = w;
}
f += wt * 125;
// 第3段階
w -= 10;
if (w <= 0) {
return (f);
}
if (w > 10) {
wt = 10;
} else {
wt = w;
}
f += wt * 140;
// 第4段階
w -= 10;
if (w <= 0) {
return (f);
}
f += w * 160;
return (f);
}
int main(void) {
int w;
while (1) {
scanf("%d", &w);
if (w == -1) {
break;
}
printf("%d\n", 4280 - fee(w));
}
return (0);
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 194
| 4
|
#include <stdio.h>
int main(void) {
int w;
int m, i;
while (scanf("%d", &w) && w != -1) {
m = 1150;
if (10 < w && w <= 20)
m = m + 125 * (w - 10);
if (20 < w && w <= 30)
m = m + 140 * (w - 20) + 1250;
if (30 < w && w <= 40)
m = m + 160 * (w - 30) + 2650;
printf("%d\n", 4280 - m);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int w;
int m, i;
while (scanf("%d", &w) && w != -1) {
m = 1150;
if (10 < w && w <= 20)
m = m + 125 * (w - 10);
if (20 < w && w <= 30)
m = m + 140 * (w - 20) + 1250;
if (30 < w)
m = m + 160 * (w - 30) + 2650;
printf("%d\n", 4280 - m);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13]]
| 0
| 124
| 4
|
#include <stdio.h>
int main(void) {
int water, bill;
scanf("%d", &water);
while (water != -1) {
bill = 1150;
if (water - 10 > 0)
bill += (water - 10) * 125;
if (water - 20 > 0)
bill += (water - 20) * 15;
if (water - 30 > 0)
bill += (water - 30) * 20;
printf("%d\n", bill - 4280);
scanf("%d", &water);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int water, bill;
scanf("%d", &water);
while (water != -1) {
bill = 1150;
if (water - 10 > 0)
bill += (water - 10) * 125;
if (water - 20 > 0)
bill += (water - 20) * 15;
if (water - 30 > 0)
bill += (water - 30) * 20;
printf("%d\n", 4280 - bill);
scanf("%d", &water);
}
return (0);
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22]]
| 0
| 117
| 4
|
int main(void) {
while (1) {
int w;
int s = 0, t = 0, f = 0;
int sum;
scanf("%d", &w);
if (w == -1)
break;
if (w > 10)
w = w - 10;
if (w > 10)
s = 10;
else if (w > 0)
s = w;
w = w - 10;
if (w > 10)
t = 10;
else if (w > 0)
t = w;
w = w - 10;
if (w > 0)
f = w;
sum = 1150 + s * 125 + t * 140 + f * 160;
printf("%d\n", 4280 - sum);
}
return 0;
}
|
int main(void) {
while (1) {
int w;
int s = 0, t = 0, f = 0;
int sum;
scanf("%d", &w);
if (w == -1)
break;
w = w - 10;
if (w > 10)
s = 10;
else if (w > 0)
s = w;
w = w - 10;
if (w > 10)
t = 10;
else if (w > 0)
t = w;
w = w - 10;
if (w > 0)
f = w;
sum = 1150 + s * 125 + t * 140 + f * 160;
printf("%d\n", 4280 - sum);
}
return 0;
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 57, 0, 121], ["-", 0, 52, 8, 9, 0, 57, 15, 23, 0, 24], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 57, 15, 23, 0, 25]]
| 0
| 157
| 6
|
#include <stdio.h>
int main(void) {
int a, b, i;
while (1) {
scanf("%d", &a);
if (a == -1)
break;
b = 0;
if (a <= 10) {
b = 1150;
} else if (10 < a <= 20) {
b = 1150;
for (i = 0; i < a - 10; i++) {
b += 125;
}
} else if (20 < a <= 30) {
b = 2400;
for (i = 0; i < a - 20; i++) {
b += 140;
}
} else if (a > 30) {
b = 3800;
for (i = 0; i < a - 30; i++) {
b += 160;
}
}
printf("%d\n", 4280 - b);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, i;
while (1) {
scanf("%d", &a);
if (a == -1)
break;
b = 0;
if (a <= 10) {
b = 1150;
} else if (a <= 20) {
b = 1150;
for (i = 0; i < a - 10; i++) {
b += 125;
}
} else if (a <= 30) {
b = 2400;
for (i = 0; i < a - 20; i++) {
b += 140;
}
} else if (a > 30) {
b = 3800;
for (i = 0; i < a - 30; i++) {
b += 160;
}
}
printf("%d\n", 4280 - b);
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 31, 13], ["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 18]]
| 0
| 177
| 4
|
#include <stdio.h>
int main() {
while (1) {
int w;
scanf("%d", &w);
if (w == -1)
break;
if (w <= 10) {
printf("%d", 4280 - 1150);
} else if (w <= 20) {
printf("%d\n", 4280 - 1150 - 125 * (w - 10));
} else if (w <= 30) {
printf("%d\n", 4280 - 1150 - 1250 - (140 * (w - 20)));
} else {
printf("%d\n", 4280 - 1150 - 1250 - 1400 - (160 * (w - 30)));
}
}
return 0;
}
|
#include <stdio.h>
int main() {
while (1) {
int w;
scanf("%d", &w);
if (w == -1)
break;
if (w <= 10) {
printf("%d\n", 4280 - 1150);
} else if (w <= 20) {
printf("%d\n", 4280 - 1150 - 125 * (w - 10));
} else if (w <= 30) {
printf("%d\n", 4280 - 1150 - 1250 - (140 * (w - 20)));
} else {
printf("%d\n", 4280 - 1150 - 1250 - 1400 - (160 * (w - 30)));
}
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 148
| 1
|
main(n) {
for (; scanf("%d", &n) + n; printf("%d\n", (n < 11 ? 626
: n < 21 ? 886 - n * 25
: n < 31 ? 936 - n * 28
: 1056 - n * 32) *
5))
;
}
|
main(n) {
for (; scanf("%d", &n) + n; printf("%d\n", (n < 11 ? 626
: n < 21 ? 876 - n * 25
: n < 31 ? 936 - n * 28
: 1056 - n * 32) *
5))
;
}
|
[["-", 31, 23, 0, 41, 75, 41, 64, 16, 31, 13], ["+", 31, 23, 0, 41, 75, 41, 64, 16, 31, 13]]
| 0
| 66
| 2
|
#include <stdio.h>
int main() {
int a;
int R;
scanf("%d", &a);
while (a != -1) {
R = 1150;
if (20 <= a) {
R += 1250;
} else if (10 <= a) {
R += (a - 10) * 125;
}
if (a >= 30) {
R += 1400;
R += (a - 30) * 160;
} else if (20 <= a) {
R += (a - 20) * 140;
}
printf("%d\n", R);
scanf("%d", &a);
}
return 0;
}
|
#include <stdio.h>
int main() {
int a;
int R;
scanf("%d", &a);
while (a != -1) {
R = 1150;
if (20 <= a) {
R += 1250;
} else if (10 <= a) {
R += (a - 10) * 125;
}
if (a >= 30) {
R += 1400;
R += (a - 30) * 160;
} else if (20 <= a) {
R += (a - 20) * 140;
}
printf("%d\n", 4280 - R);
scanf("%d", &a);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33]]
| 0
| 131
| 2
|
#include <stdio.h>
int main() {
int w;
while (1) {
scanf("%d", &w);
if (w == -1)
break;
if (w <= 10)
printf("3130\n");
else if (w <= 20)
printf("%d\d", 3130 - 125 * (w - 10));
else if (w <= 30)
printf("%d\n", 1880 - 140 * (w - 20));
else
printf("%d\n", 480 - 160 * (w - 30));
}
return 0;
}
|
#include <stdio.h>
int main() {
int w;
while (1) {
scanf("%d", &w);
if (w == -1)
break;
if (w <= 10)
printf("3130\n");
else if (w <= 20)
printf("%d\n", 3130 - 125 * (w - 10));
else if (w <= 30)
printf("%d\n", 1880 - 140 * (w - 20));
else
printf("%d\n", 480 - 160 * (w - 30));
}
return 0;
}
|
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 121
| 2
|
#include <stdio.h>
int main(void) {
int w, a;
while (scanf("%d", &w) != EOF && w != -1) {
int rates = 1150;
if (w > 30) {
rates += (1250 + 1400);
rates += (w - 30) * 160;
} else {
if (w > 20) {
rates += 1250;
rates += (w - 20) * 140;
} else if (10 < w && w < 20) {
rates += (w - 10) * 125;
}
}
printf("%d\n", 4280 - rates);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int w, a;
while (scanf("%d", &w) != EOF && w != -1) {
int rates = 1150;
if (w > 30) {
rates += (1250 + 1400);
rates += (w - 30) * 160;
} else {
if (w > 20) {
rates += 1250;
rates += (w - 20) * 140;
} else if (10 < w && w <= 20) {
rates += (w - 10) * 125;
}
}
printf("%d\n", 4280 - rates);
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 19]]
| 0
| 128
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
while (true) {
int w;
cin >> w;
if (w == -1)
break;
if (w <= 10)
cout << 4280 - (1150) << "\n";
w -= 10;
if (w <= 10 && w > 0)
cout << 4280 - (1150 + w * 125) << "\n";
w -= 10;
if (w <= 10 && w > 0)
cout << 4280 - (1150 + 10 * 125 + w * 140) << "\n";
w -= 10;
if (w >= 0)
cout << 4280 - (1150 + 10 * 125 + 10 * 140 + w * 160) << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
while (true) {
int w;
cin >> w;
if (w == -1)
break;
if (w <= 10)
cout << 4280 - 1150 << "\n";
w -= 10;
if (w <= 10 && w > 0)
cout << 4280 - (1150 + w * 125) << "\n";
w -= 10;
if (w <= 10 && w > 0)
cout << 4280 - (1150 + 10 * 125 + w * 140) << "\n";
w -= 10;
if (w > 0)
cout << 4280 - (1150 + 10 * 125 + 10 * 140 + w * 160) << "\n";
}
return 0;
}
|
[["-", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["-", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 152
| 4
|
#include <stdio.h>
int main() {
int W, T = 4280;
int d = 0, x = 0;
while (1) {
scanf("%d", &W);
if (W == -1)
break;
T = T - 1150;
if (W <= 10) {
printf("%d\n", T);
} else if (W <= 20) {
d = 125 * (W - 10);
T = T - d;
printf("%d\n", T);
} else if (W <= 30) {
d = 140 * (W - 20);
T = T - d - 1250;
printf("%d\n", T);
} else if (W > 30) {
d = 160 * (W - 30);
T = T - d - 1250 - 1400;
printf("%d\n", T);
}
}
return 0;
}
|
#include <stdio.h>
int main() {
int W, T = 4280;
int d = 0, x = 0;
while (1) {
scanf("%d", &W);
if (W == -1)
break;
T = T - 1150;
if (W <= 10) {
printf("%d\n", T);
} else if (W <= 20) {
d = 125 * (W - 10);
T = T - d;
printf("%d\n", T);
} else if (W <= 30) {
d = 140 * (W - 20);
T = T - d - 1250;
printf("%d\n", T);
} else if (W > 30) {
d = 160 * (W - 30);
T = T - d - 1250 - 1400;
printf("%d\n", T);
}
T = 4280;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 186
| 4
|
#include <bits/stdc++.h>
using namespace std;
int w;
int main() {
while (cin >> w && (~w)) {
int res = 1150;
if (w > 10) {
res += min(10, w - 10) * 125;
}
if (w > 20) {
res += min(10, w - 20) * 140;
}
if (w > 30) {
res += (w - 30) * 160;
}
cout << -4280 + res << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int w;
int main() {
while (cin >> w && (~w)) {
int res = 1150;
if (w > 10) {
res += min(10, w - 10) * 125;
}
if (w > 20) {
res += min(10, w - 20) * 140;
}
if (w > 30) {
res += (w - 30) * 160;
}
cout << 4280 - res << endl;
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 31, 13], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 13], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
| 1
| 101
| 4
|
#include <stdio.h>
#include <string.h>
int main(void) {
int a, s, d, f, g, h, i, j;
scanf("%d", &a);
while (a != -1) {
s = 4280 - 1150;
if (a > 10 && a <= 20) {
s = 4280 - (a - 10) * 125 + 1150;
}
if (a > 20 && a <= 30) {
s = 4280 - ((a - 20) * 140 + 1250 + 1150);
}
if (a > 30) {
s = 4280 - ((a - 30) * 160 + 1250 + 1400 + 1150);
}
printf("%d\n", s);
scanf("%d", &a);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int a, s, d, f, g, h, i, j;
scanf("%d", &a);
while (a != -1) {
s = 4280 - 1150;
if (a > 10 && a <= 20) {
s = 4280 - ((a - 10) * 125 + 1150);
}
if (a > 20 && a <= 30) {
s = 4280 - ((a - 20) * 140 + 1250 + 1150);
}
if (a > 30) {
s = 4280 - ((a - 30) * 160 + 1250 + 1400 + 1150);
}
printf("%d\n", s);
scanf("%d", &a);
}
return 0;
}
|
[["+", 12, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 1
| 159
| 2
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int w;
cin >> w;
if (w == -1)
break;
if (w <= 10) {
cout << 4280 - 1150 << endl;
} else if (w <= 20 && w >= 11) {
cout << 4280 - 1150 - 125 * (w - 10) << endl;
} else if (w <= 30 && w >= 21) {
cout << 4280 - 1150 - 125 * 10 - 140 * (w - 20) << endl;
} else if (w <= 40 && w >= 31) {
cout << 4280 - 1150 - 125 * 10 - 140 * 10 - 160 * (w - 10) << endl;
}
}
}
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int w;
cin >> w;
if (w == -1)
break;
if (w <= 10) {
cout << 4280 - 1150 << endl;
} else if (w <= 20 && w >= 11) {
cout << 4280 - 1150 - 125 * (w - 10) << endl;
} else if (w <= 30 && w >= 21) {
cout << 4280 - 1150 - 125 * 10 - 140 * (w - 20) << endl;
} else if (w >= 31) {
cout << 4280 - 1150 - 125 * 10 - 140 * 10 - 160 * (w - 30) << endl;
}
}
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 98], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 12, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 12, 16, 12, 16, 12, 23, 0, 16, 12, 13]]
| 1
| 148
| 6
|
#include <iostream>
using namespace std;
int main() {
int x;
while (1) {
cin >> x;
if (x == -1)
break;
else if (0 <= x && x <= 10)
cout << 4280 - 1150 << endl;
else if (11 <= x && x <= 20)
cout << 4280 - 1150 - 125 * (x - 10) << endl;
else if (21 <= x && x <= 30)
cout << 4280 - 1150 - 125 * 10 - 140 * (x - 20) << endl;
else if (31 <= x && x <= 40)
cout << 4280 - 1150 - 125 * 10 - 140 * 10 - 160 * (x - 30) << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int x;
while (1) {
cin >> x;
if (x == -1)
break;
else if (0 <= x && x <= 10)
cout << 4280 - 1150 << endl;
else if (11 <= x && x <= 20)
cout << 4280 - 1150 - 125 * (x - 10) << endl;
else if (21 <= x && x <= 30)
cout << 4280 - 1150 - 125 * 10 - 140 * (x - 20) << endl;
else if (31 <= x)
cout << 4280 - 1150 - 125 * 10 - 140 * 10 - 160 * (x - 30) << endl;
}
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 98], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 145
| 4
|
using namespace std;
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
int main() {
int n;
while (cin >> n && n != -1) {
int ans = 1150;
if (10 < n)
ans += min(10, (n - 10)) * 125;
if (20 < n)
ans += min(10, (n - 20)) * 140;
if (30 < n)
ans += min(10, (n - 30)) * 160;
cout << 4280 - ans << endl;
}
return 0;
}
|
using namespace std;
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
int main() {
int n;
while (cin >> n && n != -1) {
int ans = 1150;
if (10 < n)
ans += min(10, (n - 10)) * 125;
if (20 < n)
ans += min(10, (n - 20)) * 140;
if (30 < n)
ans += (n - 30) * 160;
cout << 4280 - ans << endl;
}
return 0;
}
|
[["-", 64, 1, 0, 11, 12, 16, 31, 2, 63, 22], ["-", 0, 11, 12, 16, 31, 2, 3, 4, 0, 13], ["-", 0, 11, 12, 16, 31, 2, 3, 4, 0, 21], ["-", 12, 16, 31, 2, 3, 4, 0, 23, 0, 24], ["-", 12, 16, 31, 2, 3, 4, 0, 23, 0, 25]]
| 1
| 118
| 5
|
#include <iostream>
using namespace std;
int main() {
int a = 4280, b, sum, ans;
while (true) {
cin >> b;
if (b == -1)
break;
if (b <= 10) {
sum = 1150;
ans = a - sum;
cout << ans << endl;
}
if (b > 10 && b <= 20) {
sum = 1150 + (b - 10) * 125;
ans = a - sum;
cout << ans << endl;
}
if (b > 20 && b <= 30) {
sum = 1150 + 1250 + (b - 20) * 140;
ans = a - sum;
cout << ans << endl;
}
if (b > 30) {
sum = 1150 + 1250 + 1600 + (b - 30) * 160;
ans = a - sum;
cout << ans << endl;
}
}
}
|
#include <iostream>
using namespace std;
int main() {
int a = 4280, b, sum, ans;
while (true) {
cin >> b;
if (b == -1)
break;
if (b <= 10) {
sum = 1150;
ans = a - sum;
cout << ans << endl;
}
if (b > 10 && b <= 20) {
sum = 1150 + (b - 10) * 125;
ans = a - sum;
cout << ans << endl;
}
if (b > 20 && b <= 30) {
sum = 1150 + 1250 + (b - 20) * 140;
ans = a - sum;
cout << ans << endl;
}
if (b > 30) {
sum = 1150 + 1250 + 1400 + (b - 30) * 160;
ans = a - sum;
cout << ans << endl;
}
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 13]]
| 1
| 175
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int w;
while (true) {
int x = 1150;
cin >> w;
if (w < 0) {
return 0;
}
w -= 10;
if (w > 0) {
x += 125 * min(10, w);
}
w -= 10;
if (w > 0) {
x += 140 * min(10, w);
}
w -= 10;
if (w > 0) {
x += 160 * min(10, w);
}
cout << 4280 - x << endl;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int w;
while (true) {
int x = 1150;
cin >> w;
if (w < 0) {
return 0;
}
w -= 10;
if (w > 0) {
x += 125 * min(10, w);
}
w -= 10;
if (w > 0) {
x += 140 * min(10, w);
}
w -= 10;
if (w > 0) {
x += 160 * w;
}
cout << 4280 - x << endl;
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 2, 63, 22], ["-", 0, 11, 12, 16, 12, 2, 3, 4, 0, 24], ["-", 0, 11, 12, 16, 12, 2, 3, 4, 0, 13], ["-", 0, 11, 12, 16, 12, 2, 3, 4, 0, 21], ["-", 0, 11, 12, 16, 12, 2, 3, 4, 0, 25]]
| 1
| 120
| 5
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int w;
while (1) {
int rs;
scanf("%d", &w);
if (w == -1) {
break;
}
if (w <= 10) {
rs = 1150;
} else if (w <= 20) {
rs = 1150 + (w % 10) * 125;
} else if (w <= 30) {
rs = 1150 + 1250 + (w % 10) * 140;
} else if (30 < w) {
rs = 1150 + 1250 + 1400 + (w % 30) * 160;
}
cout << 4280 - rs << endl;
}
return (0);
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int w;
while (1) {
int rs;
scanf("%d", &w);
if (w == -1) {
break;
}
if (w <= 10) {
rs = 1150;
} else if (w <= 20) {
rs = 1150 + (w - 10) * 125;
} else if (w <= 30) {
rs = 1150 + 1250 + (w - 20) * 140;
} else if (30 < w) {
rs = 1150 + 1250 + 1400 + (w - 30) * 160;
}
cout << 4280 - rs << endl;
}
return (0);
}
|
[["-", 12, 16, 12, 16, 31, 23, 0, 16, 17, 109], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["-", 12, 16, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 12, 13]]
| 1
| 140
| 8
|
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long lli;
const int N = 10;
const int M = 50;
const lli INF = 1LL << 40;
int w, h, f, m, o;
int dat[N][N];
lli dp[N + 1][N][1 << N][M + 1];
main() {
while (cin >> w >> h && (w | h)) {
cin >> f >> m >> o;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> dat[i][j];
fill(dp[0][0][0], dp[N + 1][0][0], -INF);
for (int i = 0; i < w; i++) {
if (o - 1 > 0) {
if (dat[0][i] > 0) {
dp[0][i][1 << i][min(m, (o - 1 + dat[0][i]))] = 0;
} else if (dat[0][i] < 0) {
if (f + dat[0][i] >= 0)
dp[0][i][1 << i][o - 1] = dat[0][i];
}
}
}
for (int i = 0; i < h - 1; i++) {
lli nm, cost;
for (int j = 0; j < (1 << w); j++) { // 2
for (int k = 1; k <= m; k++) {
for (int d = 0; d < w; d++) {
int l = w - 1, r = 0;
for (int k2 = 0; k2 < w; k2++) {
if ((j >> k2) & 1) {
l = min(l, k2);
r = max(r, k2);
}
}
if (l > 0 && k - abs(l - d) - 1 > 0) {
if (dat[i][l - 1] > 0) {
nm = min(m, (k - abs(l - d) - 1 + dat[i][l - 1]));
cost = 0;
} else if (dat[i][l - 1] < 0) {
nm = k - abs(l - d) - 1;
cost = dat[i][l - 1];
}
if (f + dp[i][d][j][k] + cost >= 0)
dp[i][l - 1][j | (1 << (l - 1))][nm] =
max(dp[i][l - 1][j | (1 << (l - 1))][nm],
dp[i][d][j][k] + cost);
}
if (r + 1 < w && k - abs(r - d) - 1 > 0) {
if (dat[i][r + 1] > 0) {
nm = min(m, (k - abs(r - d) - 1 + dat[i][r + 1]));
cost = 0;
} else if (dat[i][r + 1] < 0) {
nm = k - abs(r - d) - 1;
cost = dat[i][r + 1];
}
if (f + dp[i][d][j][k] + cost >= 0)
dp[i][r + 1][j | (1 << (r + 1))][nm] =
max(dp[i][r + 1][j | (1 << (r + 1))][nm],
dp[i][d][j][k] + cost);
}
for (int p = l; p <= r; p++) {
if (k - abs(p - d) - 1 > 0) {
if (dat[i + 1][p] > 0) {
nm = min(m, (k - abs(p - d) - 1 + dat[i + 1][p]));
cost = 0;
} else if (dat[i + 1][p] < 0) {
nm = k - abs(p - d) - 1;
cost = dat[i + 1][p];
}
if (f + dp[i][d][j][k] + cost >= 0)
dp[i + 1][p][1 << p][nm] =
max(dp[i + 1][p][1 << p][nm], dp[i][d][j][k] + cost);
}
}
}
}
}
}
lli valM = -INF;
for (int j = 0; j < (1 << w); j++) {
for (int k = 1; k <= m; k++) {
for (int d = 0; d < w; d++) {
valM = max(valM, dp[h - 1][d][j][k]);
// cout << d << ' ' << j << ' ' << k << ' ' << dp[2][d][j][k] << endl;
}
}
}
if (f + valM < 0) {
cout << "NA" << endl;
} else {
cout << abs(valM) << endl;
}
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long lli;
const int N = 10;
const int M = 50;
const lli INF = 1LL << 40;
int w, h, f, m, o;
int dat[N][N];
lli dp[N + 1][N][1 << N][M + 1];
main() {
while (cin >> w >> h && (w | h)) {
cin >> f >> m >> o;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> dat[i][j];
fill(dp[0][0][0], dp[N + 1][0][0], -INF);
for (int i = 0; i < w; i++) {
if (o - 1 > 0) {
if (dat[0][i] >= 0) {
dp[0][i][1 << i][min(m, (o - 1 + dat[0][i]))] = 0;
} else if (dat[0][i] < 0) {
if (f + dat[0][i] >= 0)
dp[0][i][1 << i][o - 1] = dat[0][i];
}
}
}
for (int i = 0; i < h - 1; i++) {
lli nm, cost;
for (int j = 0; j < (1 << w); j++) { // 2
for (int k = 1; k <= m; k++) {
for (int d = 0; d < w; d++) {
int l = w - 1, r = 0;
for (int k2 = 0; k2 < w; k2++) {
if ((j >> k2) & 1) {
l = min(l, k2);
r = max(r, k2);
}
}
if (l > 0 && k - abs(l - d) - 1 > 0) {
if (dat[i][l - 1] >= 0) {
nm = min(m, (k - abs(l - d) - 1 + dat[i][l - 1]));
cost = 0;
} else if (dat[i][l - 1] < 0) {
nm = k - abs(l - d) - 1;
cost = dat[i][l - 1];
}
if (f + dp[i][d][j][k] + cost >= 0)
dp[i][l - 1][j | (1 << (l - 1))][nm] =
max(dp[i][l - 1][j | (1 << (l - 1))][nm],
dp[i][d][j][k] + cost);
}
if (r + 1 < w && k - abs(r - d) - 1 > 0) {
if (dat[i][r + 1] >= 0) {
nm = min(m, (k - abs(r - d) - 1 + dat[i][r + 1]));
cost = 0;
} else if (dat[i][r + 1] < 0) {
nm = k - abs(r - d) - 1;
cost = dat[i][r + 1];
}
if (f + dp[i][d][j][k] + cost >= 0)
dp[i][r + 1][j | (1 << (r + 1))][nm] =
max(dp[i][r + 1][j | (1 << (r + 1))][nm],
dp[i][d][j][k] + cost);
}
for (int p = l; p <= r; p++) {
if (k - abs(p - d) - 1 > 0) {
if (dat[i + 1][p] >= 0) {
nm = min(m, (k - abs(p - d) - 1 + dat[i + 1][p]));
cost = 0;
} else if (dat[i + 1][p] < 0) {
nm = k - abs(p - d) - 1;
cost = dat[i + 1][p];
}
if (f + dp[i][d][j][k] + cost >= 0)
dp[i + 1][p][1 << p][nm] =
max(dp[i + 1][p][1 << p][nm], dp[i][d][j][k] + cost);
}
}
}
}
}
}
lli valM = -INF;
for (int j = 0; j < (1 << w); j++) {
for (int k = 1; k <= m; k++) {
for (int d = 0; d < w; d++) {
valM = max(valM, dp[h - 1][d][j][k]);
// cout << d << ' ' << j << ' ' << k << ' ' << dp[2][d][j][k] << endl;
}
}
}
if (f + valM < 0) {
cout << "NA" << endl;
} else {
cout << abs(valM) << endl;
}
}
}
|
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 1,162
| 8
|
#include <stdio.h>
int main() {
int n, a, b, t, ans = 0;
int i, j, k, l, p, q, far = 0, sta[20] = {0}, now = 0, tail = 0, count;
int lis
[20]
[23]; // 0-19隣接リスト,20隣接する島への時間の合計,21隣接する島の数,22島1からの時間
scanf("%d", &n);
while (n > 0) {
for (p = 0; p < 20; p++) {
for (q = 0; q < 23; q++) {
lis[p][q] = 0;
}
}
for (i = 0; i < n - 1; i++) {
scanf("%d %d %d", &a, &b, &t);
lis[a - 1][b - 1] = t;
lis[a - 1][20] += t;
lis[a - 1][21]++;
lis[b - 1][a - 1] = t;
lis[b - 1][20] += t;
lis[b - 1][21]++;
}
for (j = 0; j < n; j++) {
if (lis[j][21] >= 2 || j == 0)
ans += lis[j][20];
else if (lis[j][21] == 1)
ans -= lis[j][20];
}
while (now >= 0) {
count = 0;
for (k = 0; k < n; k++) {
if (lis[sta[now]][k] > 0 && lis[k][21] >= 2 && lis[k][22] == 0) {
lis[k][22] = lis[sta[now]][k] + lis[sta[now]][22];
sta[tail + 1] = k;
tail++;
count++;
}
}
if (count == 0)
tail--;
now = tail;
}
for (l = 0; l < n; l++) {
if (lis[l][22] > far)
far = lis[l][22];
}
ans -= far;
printf("%d\n", ans);
scanf("%d", &n);
far = 0;
now = 0;
tail = 0;
ans = 0;
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, a, b, t, ans = 0;
int i, j, k, l, p, q, far = 0, sta[20] = {0}, now = 0, tail = 0, count;
int lis
[20]
[23]; // 0-19隣接リスト,20隣接する島への時間の合計,21隣接する島の数,22島1からの時間
scanf("%d", &n);
while (n > 0) {
for (p = 0; p < 20; p++) {
for (q = 0; q < 23; q++) {
lis[p][q] = 0;
}
}
for (i = 0; i < n - 1; i++) {
scanf("%d %d %d", &a, &b, &t);
lis[a - 1][b - 1] = t;
lis[a - 1][20] += t;
lis[a - 1][21]++;
lis[b - 1][a - 1] = t;
lis[b - 1][20] += t;
lis[b - 1][21]++;
}
for (j = 0; j < n; j++) {
if (lis[j][21] >= 2 || j == 0)
ans += lis[j][20];
else if (lis[j][21] == 1)
ans -= lis[j][20];
}
while (now >= 0) {
count = 0;
for (k = 0; k < n; k++) {
if (lis[sta[now]][k] > 0 && lis[k][21] >= 2 && lis[k][22] == 0 &&
k > 0) {
lis[k][22] = lis[sta[now]][k] + lis[sta[now]][22];
sta[tail + 1] = k;
tail++;
count++;
}
}
if (count == 0)
tail--;
now = tail;
}
for (l = 0; l < n; l++) {
if (lis[l][22] > far)
far = lis[l][22];
}
ans -= far;
printf("%d\n", ans);
scanf("%d", &n);
far = 0;
now = 0;
tail = 0;
ans = 0;
}
return 0;
}
|
[["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13]]
| 0
| 498
| 4
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, m) for (int(i) = (m); (i) >= 0; (i)--)
#define REPONE(i, n) FOR(i, 1, n + 1)
#define ALL(a) (a).begin(), (a).end()
#define MP make_pair
#define X first.first
#define Y first.second
typedef pair<int, int> P;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
int rtime[21][21];
vector<int> leaf;
int N, ANS = 0;
int dfs(int from) {
int dmax = 0;
REPONE(i, N) {
if (rtime[from][i] != INF) {
rtime[i][from] = INF;
chmax(dmax, rtime[from][i] + dfs(i));
}
}
return dmax;
}
signed main() {
while (cin >> N, N) {
fill(rtime[0], rtime[21], INF);
ANS = 0;
REP(i, N - 1) {
int from, to, t;
cin >> from >> to >> t;
rtime[from][to] = t;
rtime[to][from] = t;
ANS += 2 * t;
}
REPONE(i, N) {
int cnt = 0, idx;
REPONE(j, N) {
if (rtime[i][j] != INF) {
cnt++;
idx = j;
}
}
if (cnt == 1 && i != 1) {
ANS -= 2 * rtime[i][idx];
rtime[i][idx] = rtime[idx][i] = INF;
}
}
cout << ANS - dfs(1) << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, m) for (int(i) = (m); (i) >= 0; (i)--)
#define REPONE(i, n) FOR(i, 1, n + 1)
#define ALL(a) (a).begin(), (a).end()
#define MP make_pair
#define X first.first
#define Y first.second
typedef pair<int, int> P;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
int rtime[21][21];
vector<int> leaf;
int N, ANS = 0;
int dfs(int from) {
int dmax = 0;
REPONE(i, N) {
if (rtime[from][i] < INF) {
rtime[i][from] = INF;
chmax(dmax, rtime[from][i] + dfs(i));
}
}
return dmax;
}
signed main() {
while (cin >> N, N) {
fill(rtime[0], rtime[21], INF);
ANS = 0;
REP(i, N - 1) {
int from, to, t;
cin >> from >> to >> t;
rtime[from][to] = t;
rtime[to][from] = t;
ANS += 2 * t;
}
REPONE(i, N) {
int cnt = 0, idx;
REPONE(j, N) {
if (rtime[i][j] != INF) {
cnt++;
idx = j;
}
}
if (cnt == 1 && i != 1) {
ANS -= 2 * rtime[i][idx];
rtime[i][idx] = rtime[idx][i] = INF + 1;
}
}
cout << ANS - dfs(1) << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 1, 0, 11, 12, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 11, 12, 16, 12, 13]]
| 1
| 427
| 4
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct edge {
int to, cost;
};
int n, a, b, c;
int main() {
while (cin >> n, n) {
vector<vector<edge>> G(n);
for (int i = 0; i < n - 1; i++) {
cin >> a >> b >> c;
a--, b--;
G[a].push_back(edge{b, c});
G[b].push_back(edge{a, c});
}
vector<bool> lv(n, false);
for (int i = 1; i < n; i++) {
if (G[i].size() == 1)
lv[i] = true;
}
vector<int> v(n, 999999999);
v[0] = 0;
queue<int> que;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
for (edge e : G[u]) {
if (v[e.to] > v[u] + e.cost) {
v[e.to] = v[u] + e.cost;
que.push(e.to);
}
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
if (lv[i])
continue;
for (edge j : G[i]) {
if (!lv[j.to])
sum += j.cost;
}
}
int res = 0;
for (int i = 0; i < n; i++) {
if (!lv[i])
res = max(res, v[i]);
}
cout << sum * 2 - res << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct edge {
int to, cost;
};
int n, a, b, c;
int main() {
while (cin >> n, n) {
vector<vector<edge>> G(n);
for (int i = 0; i < n - 1; i++) {
cin >> a >> b >> c;
a--, b--;
G[a].push_back(edge{b, c});
G[b].push_back(edge{a, c});
}
vector<bool> lv(n, false);
for (int i = 1; i < n; i++) {
if (G[i].size() == 1)
lv[i] = true;
}
vector<int> v(n, 999999999);
v[0] = 0;
queue<int> que;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
for (edge e : G[u]) {
if (v[e.to] > v[u] + e.cost) {
v[e.to] = v[u] + e.cost;
que.push(e.to);
}
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
if (lv[i])
continue;
for (edge j : G[i]) {
if (!lv[j.to])
sum += j.cost;
}
}
int res = 0;
for (int i = 0; i < n; i++) {
if (!lv[i])
res = max(res, v[i]);
}
cout << sum - res << endl;
}
return 0;
}
|
[["-", 0, 16, 31, 16, 12, 16, 31, 16, 17, 48], ["-", 0, 16, 31, 16, 12, 16, 31, 16, 12, 13]]
| 1
| 394
| 2
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
constexpr int MAX_N = 20;
int N, ans = 0, bridges[MAX_N][MAX_N] = {};
int dfs(const int &pos = 0);
int main() {
while (true) {
scanf("%d", &N);
if (N == 0) {
break;
}
ans = 0;
REP(i, N) {
REP(j, N) { bridges[i][j] = 0; }
}
REP(i, N - 1) {
int a, b, t;
scanf("%d%d%d", &a, &b, &t);
--a, --b;
bridges[a][b] = bridges[b][a] = t;
ans += t * 2;
}
FOR(i, 1, N) {
int count = 0, tmp;
REP(j, N) {
if (bridges[i][j] != 0) {
++count;
tmp = j;
}
}
if (count == 1) {
ans -= bridges[i][tmp] * 2;
bridges[i][tmp] = bridges[tmp][i] = 0;
}
}
printf("%d\n", ans - dfs());
}
return 0;
}
int dfs(const int &pos) {
int res = 0;
REP(i, N) {
if (bridges[pos][i] != 0) {
bridges[i][pos] = 0;
res = std::max(res, dfs(i) + bridges[pos][i]);
}
}
return res;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
constexpr int MAX_N = 20;
int N, ans = 0, bridges[MAX_N][MAX_N] = {};
int dfs(const int &pos = 0);
int main() {
while (true) {
scanf("%d", &N);
if (N == 0) {
break;
}
ans = 0;
REP(i, N) {
REP(j, N) { bridges[i][j] = 0; }
}
REP(i, N - 1) {
int a, b, t;
scanf("%d%d%d", &a, &b, &t);
--a, --b;
bridges[a][b] = bridges[b][a] = t;
ans += t * 2;
}
FOR(i, 1, N) {
int count = 0, tmp;
REP(j, N) {
if (bridges[i][j] != 0) {
++count;
tmp = j;
}
}
if (count == 1) {
ans -= bridges[i][tmp] * 2;
bridges[i][tmp] = bridges[tmp][i] = -1;
}
}
printf("%d\n", ans - dfs());
}
return 0;
}
int dfs(const int &pos) {
int res = 0;
REP(i, N) {
if (bridges[pos][i] != 0) {
bridges[i][pos] = 0;
res = std::max(res, dfs(i) + bridges[pos][i]);
}
}
return res;
}
|
[["-", 64, 9, 0, 1, 0, 11, 12, 11, 12, 13], ["+", 64, 9, 0, 1, 0, 11, 12, 11, 12, 13]]
| 1
| 377
| 2
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
vector<P> E[20], G[20];
bool used[20];
void C(int u) {
used[u] = true;
for (P v : E[u]) {
if (0 < G[v.second].size() && !used[v.second]) {
G[u].push_back(v);
C(v.second);
}
}
}
int dfs(int u) {
int sum = 0;
for (P v : G[u]) {
if (0 < G[v.second].size())
sum += dfs(v.second) + v.first * 2;
}
return sum;
}
int dfs2(int u) {
int Max = 0;
for (P v : G[u]) {
if (0 < G[v.second].size())
Max = max(Max, dfs2(v.second) + v.first);
}
return Max;
}
int main() {
int n;
while (scanf("%d", &n), n) {
rep(i, n) {
E[i].clear();
G[i].clear();
}
rep(i, n - 1) {
int a, b, t;
scanf("%d%d%d", &a, &b, &t);
a--;
b--;
E[a].push_back(P(t, b));
E[b].push_back(P(t, a));
}
memset(used, 0, sizeof(used));
C(0);
printf("%d\n", dfs(0) - dfs2(0));
}
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
vector<P> E[20], G[20];
bool used[20];
void C(int u) {
used[u] = true;
for (P v : E[u]) {
if (0 < E[v.second].size() && !used[v.second]) {
G[u].push_back(v);
C(v.second);
}
}
}
int dfs(int u) {
int sum = 0;
for (P v : G[u]) {
if (0 < G[v.second].size())
sum += dfs(v.second) + v.first * 2;
}
return sum;
}
int dfs2(int u) {
int Max = 0;
for (P v : G[u]) {
if (0 < G[v.second].size())
Max = max(Max, dfs2(v.second) + v.first);
}
return Max;
}
int main() {
int n;
while (scanf("%d", &n), n) {
rep(i, n) {
E[i].clear();
G[i].clear();
}
rep(i, n - 1) {
int a, b, t;
scanf("%d%d%d", &a, &b, &t);
a--;
b--;
E[a].push_back(P(t, b));
E[b].push_back(P(t, a));
}
memset(used, 0, sizeof(used));
C(0);
printf("%d\n", dfs(0) - dfs2(0));
}
}
|
[["-", 31, 16, 12, 2, 63, 118, 28, 69, 28, 22], ["+", 31, 16, 12, 2, 63, 118, 28, 69, 28, 22]]
| 1
| 387
| 2
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define P pair<int, int> // cost to
using namespace std;
bool X[20];
vector<P> rinsetu[20];
bool S[20];
int MAX;
int saiki(int a, int b) {
MAX = max(MAX, b);
S[a] = true;
for (P i : rinsetu[a]) {
if (S[i.second] == false && X[i.second]) {
saiki(i.second, b + i.first);
}
}
S[b] = false;
}
signed main() {
int a;
while (cin >> a, a) {
memset(X, true, sizeof(X));
int sum = 0;
for (int b = 0; b < a; b++) {
rinsetu[b].clear();
}
for (int b = 1; b < a; b++) {
int c, d, e;
cin >> c >> d >> e;
c--;
d--;
rinsetu[c].push_back(P(e, d));
rinsetu[d].push_back(P(e, c));
sum += e * 2;
}
for (int i = 1; i < a; i++) {
if (rinsetu[i].size() == 1) {
sum -= rinsetu[i][0].first * 2;
X[i] = false;
}
}
memset(S, false, sizeof(S));
MAX = 0;
saiki(0, 0);
cout << sum - MAX << endl;
}
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define P pair<int, int> // cost to
using namespace std;
bool X[20];
vector<P> rinsetu[20];
bool S[20];
int MAX;
int saiki(int a, int b) {
MAX = max(MAX, b);
S[a] = true;
for (P i : rinsetu[a]) {
if (S[i.second] == false && X[i.second]) {
saiki(i.second, b + i.first);
}
}
S[a] = false;
}
signed main() {
int a;
while (cin >> a, a) {
memset(X, true, sizeof(X));
int sum = 0;
for (int b = 0; b < a; b++) {
rinsetu[b].clear();
}
for (int b = 1; b < a; b++) {
int c, d, e;
cin >> c >> d >> e;
c--;
d--;
rinsetu[c].push_back(P(e, d));
rinsetu[d].push_back(P(e, c));
sum += e * 2;
}
for (int i = 1; i < a; i++) {
if (rinsetu[i].size() == 1) {
sum -= rinsetu[i][0].first * 2;
X[i] = false;
}
}
memset(S, false, sizeof(S));
MAX = 0;
saiki(0, 0);
cout << sum - MAX << endl;
}
}
|
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
| 1
| 349
| 2
|
// 2011/01/10 Tazoe
#include <iostream>
using namespace std;
void swp(int abt[20][3], int i, int j) {
abt[19][0] = abt[i][0];
abt[19][1] = abt[i][1];
abt[19][2] = abt[i][2];
abt[i][0] = abt[j][0];
abt[i][1] = abt[j][1];
abt[i][2] = abt[j][2];
abt[j][0] = abt[19][0];
abt[j][1] = abt[19][1];
abt[j][2] = abt[19][2];
}
void DFS(int abt[20][3], int N, int a, int t, int &t_max) {
if (t_max < t)
t_max = t;
for (int i = 0; i < N - 1; i++)
if (abt[i][0] == a)
DFS(abt, N, abt[i][1], t + abt[i][2], t_max);
}
int main() {
while (true) {
int N;
cin >> N;
if (N == 0)
break;
int abt[20][3];
for (int i = 0; i < N - 1; i++)
cin >> abt[i][0] >> abt[i][1] >> abt[i][2];
int que[20] = {1};
int quh = 0;
int qut = 1;
for (int i = 0; i < N - 1; i++) {
bool flg = false;
for (int j = i; j < N - 1; j++) {
if (abt[j][0] != que[quh] && abt[j][1] != que[quh])
continue;
if (abt[j][1] == que[quh]) {
int tmp = abt[j][0];
abt[j][0] = abt[j][1];
abt[j][1] = tmp;
}
swp(abt, i, j);
que[qut++] = abt[i][1];
flg = true;
break;
}
if (!flg)
quh++;
}
for (int i = 0; i < N - 1; i++) {
bool flg = false;
for (int j = i + 1; j < N - 1; j++)
if (abt[i][1] == abt[j][0]) {
flg = true;
break;
}
if (flg)
abt[i][2] *= 2;
else
abt[i][2] = 0;
}
int t_max = -1;
DFS(abt, N, 1, 0, t_max);
int sum = 0;
for (int i = 0; i < N - 1; i++)
sum += abt[i][2];
sum -= t_max / 2;
cout << sum << endl;
}
return 0;
}
|
// 2011/01/10 Tazoe
#include <iostream>
using namespace std;
void swp(int abt[20][3], int i, int j) {
abt[19][0] = abt[i][0];
abt[19][1] = abt[i][1];
abt[19][2] = abt[i][2];
abt[i][0] = abt[j][0];
abt[i][1] = abt[j][1];
abt[i][2] = abt[j][2];
abt[j][0] = abt[19][0];
abt[j][1] = abt[19][1];
abt[j][2] = abt[19][2];
}
void DFS(int abt[20][3], int N, int a, int t, int &t_max) {
if (t_max < t)
t_max = t;
for (int i = 0; i < N - 1; i++)
if (abt[i][0] == a)
DFS(abt, N, abt[i][1], t + abt[i][2], t_max);
}
int main() {
while (true) {
int N;
cin >> N;
if (N == 0)
break;
int abt[20][3];
for (int i = 0; i < N - 1; i++)
cin >> abt[i][0] >> abt[i][1] >> abt[i][2];
int que[20] = {1};
int quh = 0;
int qut = 1;
for (int i = 0; i < N - 1; i++) {
bool flg = false;
for (int j = i; j < N - 1; j++) {
if (abt[j][0] != que[quh] && abt[j][1] != que[quh])
continue;
if (abt[j][1] == que[quh]) {
int tmp = abt[j][0];
abt[j][0] = abt[j][1];
abt[j][1] = tmp;
}
swp(abt, i, j);
que[qut++] = abt[i][1];
flg = true;
break;
}
if (!flg) {
quh++;
i--;
}
}
for (int i = 0; i < N - 1; i++) {
bool flg = false;
for (int j = i + 1; j < N - 1; j++)
if (abt[i][1] == abt[j][0]) {
flg = true;
break;
}
if (flg)
abt[i][2] *= 2;
else
abt[i][2] = 0;
}
int t_max = -1;
DFS(abt, N, 1, 0, t_max);
int sum = 0;
for (int i = 0; i < N - 1; i++)
sum += abt[i][2];
sum -= t_max / 2;
cout << sum << endl;
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 27, 17, 68], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 679
| 5
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
inline bool valid(int x, int y, int W, int H) {
return (x >= 0 && y >= 0 && x < W && y < H);
}
typedef unsigned long long ull;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int W, H, C;
int grid[10][10];
vector<int> G[100];
unordered_set<ull> used[100];
bool dfs(int u, ull s) {
if (s == (1ULL << C) - 1) {
for (auto v : G[0])
if (v == u)
return true;
return false;
}
if (used[u].count(s))
return false;
// u = 0 にいけない
{
bool any = true;
for (auto v : G[0])
if (!(s & (1ULL << v)))
any = false;
if (any)
return false;
}
// のこりの頂点の次数が1以下の個数を数える
int low_degrees = 0;
REP(i, C) if (!(s & (1ULL << i))) {
int deg = 0;
for (auto v : G[i])
if (!(s & (1ULL << v)))
deg++;
if (deg <= 1)
low_degrees += 1;
if (low_degrees >= 3)
return false;
}
used[u].insert(s);
// のこりの頂点が連結かどうか
queue<int> que;
ull used_s = s;
que.push(u);
while (!que.empty()) {
int u = que.front();
que.pop();
REP(i, G[u].size()) {
int v = G[u][i];
if (used_s & (1ULL << v))
continue;
used_s |= 1ULL << v;
que.push(v);
}
}
if (used_s != (1ULL << C) - 1) {
return false;
}
for (auto v : G[u]) {
if (s & (1ULL << v))
continue;
if (dfs(v, s | (1ULL << v)))
return true;
}
return false;
}
bool dfs_naive(int u, ull s) {
if (s == (1ULL << C) - 1) {
for (auto v : G[0])
if (v == u)
return true;
return false;
}
for (auto v : G[u]) {
if (s & (1ULL << v))
continue;
if (dfs_naive(v, s | (1ULL << v))) {
// printf("%d->%d\n", u, v);
return true;
}
}
return false;
}
bool solve(int W, int H) {
C = 0;
int id[10][10];
REP(y, H) REP(x, W) {
if (grid[y][x] == 0) {
id[y][x] = C++;
}
}
REP(i, C) G[i].clear();
REP(y, H) REP(x, W) if (grid[y][x] == 0) {
REP(r, 4) {
int nx = x + dx[r];
int ny = y + dy[r];
if (valid(nx, ny, W, H) && grid[ny][nx] == 0)
G[id[y][x]].push_back(id[ny][nx]);
}
}
/*
REP(i, 100) used[i].clear();
if(dfs(0, 1) != dfs_naive(0, 1)){
REP(y, H) {
REP(x, W) cout << grid[y][x] << " ";
cout << endl;
}
REP(i, 100) used[i].clear();
cout << dfs(0, 1) << endl;
cout << dfs_naive(0, 1) << endl;
assert(false);
}
*/
REP(i, C) used[i].clear();
if (C > 0 && (C == 1 || dfs(0, 1))) {
return true;
} else {
return false;
}
}
int main() {
/*
REP(_, 100000){
int W = rand() % 5 + 1;
int H = rand() % 5 + 1;
REP(y, H) REP(x, W) grid[y][x] = rand() % 2;
solve(W, H);
}
*/
while (cin >> W >> H && W) {
REP(y, H) REP(x, W) cin >> grid[y][x];
if (solve(W, H))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
inline bool valid(int x, int y, int W, int H) {
return (x >= 0 && y >= 0 && x < W && y < H);
}
typedef unsigned long long ull;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int W, H, C;
int grid[10][10];
vector<int> G[100];
unordered_set<ull> used[100];
bool dfs(int u, ull s) {
if (s == (1ULL << C) - 1) {
for (auto v : G[0])
if (v == u)
return true;
return false;
}
if (used[u].count(s))
return false;
// u = 0 にいけない
{
bool any = true;
for (auto v : G[0])
if (!(s & (1ULL << v)))
any = false;
if (any)
return false;
}
// のこりの頂点の次数が1以下の個数を数える
int low_degrees = 0;
REP(i, C) if (!(s & (1ULL << i))) {
int deg = 0;
for (auto v : G[i])
if (!(s & (1ULL << v)))
deg++;
if (deg <= 1)
low_degrees += 1;
if (low_degrees >= 3)
return false;
}
used[u].insert(s);
// のこりの頂点が連結かどうか
queue<int> que;
ull used_s = s;
que.push(u);
while (!que.empty()) {
int u = que.front();
que.pop();
REP(i, G[u].size()) {
int v = G[u][i];
if (used_s & (1ULL << v))
continue;
used_s |= 1ULL << v;
que.push(v);
}
}
if (used_s != (1ULL << C) - 1) {
return false;
}
for (auto v : G[u]) {
if (s & (1ULL << v))
continue;
if (dfs(v, s | (1ULL << v)))
return true;
}
return false;
}
bool dfs_naive(int u, ull s) {
if (s == (1ULL << C) - 1) {
for (auto v : G[0])
if (v == u)
return true;
return false;
}
for (auto v : G[u]) {
if (s & (1ULL << v))
continue;
if (dfs_naive(v, s | (1ULL << v))) {
// printf("%d->%d\n", u, v);
return true;
}
}
return false;
}
bool solve(int W, int H) {
C = 0;
int id[10][10];
REP(y, H) REP(x, W) {
if (grid[y][x] == 0) {
id[y][x] = C++;
}
}
REP(i, C) G[i].clear();
REP(y, H) REP(x, W) if (grid[y][x] == 0) {
REP(r, 4) {
int nx = x + dx[r];
int ny = y + dy[r];
if (valid(nx, ny, W, H) && grid[ny][nx] == 0)
G[id[y][x]].push_back(id[ny][nx]);
}
}
/*
REP(i, 100) used[i].clear();
if(dfs(0, 1) != dfs_naive(0, 1)){
REP(y, H) {
REP(x, W) cout << grid[y][x] << " ";
cout << endl;
}
REP(i, 100) used[i].clear();
cout << dfs(0, 1) << endl;
cout << dfs_naive(0, 1) << endl;
assert(false);
}
*/
REP(i, C) used[i].clear();
if (C > 3 && (C == 1 || dfs(0, 1))) {
return true;
} else {
return false;
}
}
int main() {
/*
REP(_, 100000){
int W = rand() % 5 + 1;
int H = rand() % 5 + 1;
REP(y, H) REP(x, W) grid[y][x] = rand() % 2;
solve(W, H);
}
*/
while (cin >> W >> H && W) {
REP(y, H) REP(x, W) cin >> grid[y][x];
if (solve(W, H))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13]]
| 1
| 914
| 2
|
#include <stdio.h>
int main(void) {
int t;
int n;
while (scanf("%d", &t), t != 0) {
scanf("%d", &n);
while (n-- > 0) {
int s, f;
scanf("%d %d", &s, &f);
t -= f - s;
}
if (t == 0) {
puts("OK");
} else {
printf("%d\n", t);
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int t;
int n;
while (scanf("%d", &t), t != 0) {
scanf("%d", &n);
while (n-- > 0) {
int s, f;
scanf("%d %d", &s, &f);
t -= f - s;
}
if (t <= 0) {
puts("OK");
} else {
printf("%d\n", t);
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 19]]
| 0
| 107
| 2
|
#include <stdio.h>
int main(void) {
int t, n, s, f, time, i;
scanf("%d", &t);
while (t) {
time = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &s, &f);
time += f - s;
}
if (time >= t) {
puts("OK");
} else {
printf("%d", t - time);
}
scanf("%d", &t);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int t, n, s, f, time, i;
scanf("%d", &t);
while (t) {
time = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &s, &f);
time += f - s;
}
if (time >= t) {
puts("OK");
} else {
printf("%d\n", t - time);
}
scanf("%d", &t);
}
return (0);
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 130
| 1
|
#include <stdio.h>
int main(void) {
int t, n, s, f, sum;
int i;
while (1) {
sum = 0;
scanf("%d", &t);
if (t == 0)
break;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &s, &f);
sum += f - s;
}
if (sum >= t)
printf("OK\n");
else
printf("%d", t - sum);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int t, n, s, f, sum;
int i;
while (1) {
sum = 0;
scanf("%d", &t);
if (t == 0)
break;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &s, &f);
sum += f - s;
}
if (sum >= t)
printf("OK\n");
else
printf("%d\n", t - sum);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 124
| 1
|
#include <stdio.h>
int main(void) {
int t, n, i, s, e, zen = 0;
while (1) {
scanf("%d", &t);
if (t == 0)
break;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &s, &e);
zen += e - s;
}
if (zen >= t)
printf("OK\n");
else
printf("%d\n", t - zen);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int t, n, i, s, e, zen = 0;
while (1) {
scanf("%d", &t);
if (t == 0)
break;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &s, &e);
zen += e - s;
}
if (zen >= t)
printf("OK\n");
else
printf("%d\n", t - zen);
zen = 0;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 0
| 122
| 4
|
#include <stdio.h>
int main() {
int n;
int t;
int i;
int start;
int stop;
int time = 0;
while (scanf("%d", &t) != 0) {
if (t == 0)
break;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &start, &stop);
time += stop - start;
}
if (t <= time) {
printf("OK\n");
} else {
printf("%d\n", n - time);
}
time = 0;
}
return 0;
}
|
#include <stdio.h>
int main() {
int n;
int t;
int i;
int start;
int stop;
int time = 0;
while (scanf("%d", &t) != 0) {
if (t == 0)
break;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &start, &stop);
time += stop - start;
}
if (t <= time) {
printf("OK\n");
} else {
printf("%d\n", t - time);
}
time = 0;
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22]]
| 0
| 134
| 2
|
#include <stdio.h>
int main(void) {
int i, t, n, s, f, total;
/*
1行目 1日の目標時間t(整数)
2行目 勉強の回数 n(整数)
3行目 第1の勉強の開始時刻s 終了時刻f(整数 整数;半角空白区切り)
:
n+2行目 第nの勉強の開始時刻s 終了時刻f
*/
while (scanf("%d\n", &t) == 1) {
if (!t)
break;
total = 0;
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
scanf("%d %d\n", &s, &f);
total = total + f - s;
}
total -= t;
if (total > 0) {
printf("%d\n", total);
} else {
printf("OK\n");
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int i, t, n, s, f, total;
/*
1行目 1日の目標時間t(整数)
2行目 勉強の回数 n(整数)
3行目 第1の勉強の開始時刻s 終了時刻f(整数 整数;半角空白区切り)
:
n+2行目 第nの勉強の開始時刻s 終了時刻f
*/
while (scanf("%d\n", &t) == 1) {
if (!t)
break;
total = 0;
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
scanf("%d %d\n", &s, &f);
total = total + f - s;
}
t -= total;
if (t > 0) {
printf("%d\n", t);
} else {
printf("OK\n");
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 110], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 110], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 22], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 0
| 135
| 8
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.