output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the minimum number of watering operations required to satisfy the
condition.
* * * | s814769945 | Runtime Error | p03147 | Input is given from Standard Input in the following format:
N
h_1 h_2 h_3 ...... h_N | n=int(input())
h=[int(i) for i input().split()]
j=0
ans=0
while True:
if h[0]>j:
ans+=1
for i in range(1,n):
if h[i-1]<=j and h [i]>j:
ans+=1
j+=1
if j==max(h):
break
print(ans) | Statement
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the
heights of all flowers are 0. You are given a sequence
h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of
Flower k to h_k for all k (1 \leq k \leq N), by repeating the following
"watering" operation:
* Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.
Find the minimum number of watering operations required to satisfy the
condition. | [{"input": "4\n 1 2 2 1", "output": "2\n \n\nThe minimum number of watering operations required is 2. One way to achieve it\nis:\n\n * Perform the operation with (l,r)=(1,3).\n * Perform the operation with (l,r)=(2,4).\n\n* * *"}, {"input": "5\n 3 1 2 3 1", "output": "5\n \n\n* * *"}, {"input": "8\n 4 23 75 0 23 96 50 100", "output": "221"}] |
Print the minimum number of watering operations required to satisfy the
condition.
* * * | s995497978 | Wrong Answer | p03147 | Input is given from Standard Input in the following format:
N
h_1 h_2 h_3 ...... h_N | N = int(input())
inList = [int(s) for s in input().split(" ")]
ans = 0
def calcMizuyari(inList, prevMizu):
minNum = 101
minidx = -1
mizuSum = 0
for i, x in enumerate(inList):
if x < minNum:
minNum = x
minidx = i
if prevMizu < minNum:
mizuSum += minNum - prevMizu
else:
mizuSum = prevMizu
# print(inList)
# print(minNum,minidx,mizuSum)
if 0 < minidx:
mizuSum1 = calcMizuyari(inList[0:minidx], mizuSum) - prevMizu
else:
mizuSum1 = 0
if minidx + 1 < len(inList):
mizuSum2 = calcMizuyari(inList[minidx + 1 :], mizuSum) - prevMizu
else:
mizuSum2 = 0
# print("ans:"+str(mizuSum+mizuSum1 + mizuSum2))
return mizuSum + mizuSum1 + mizuSum2
print(calcMizuyari(inList, ans))
| Statement
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the
heights of all flowers are 0. You are given a sequence
h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of
Flower k to h_k for all k (1 \leq k \leq N), by repeating the following
"watering" operation:
* Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.
Find the minimum number of watering operations required to satisfy the
condition. | [{"input": "4\n 1 2 2 1", "output": "2\n \n\nThe minimum number of watering operations required is 2. One way to achieve it\nis:\n\n * Perform the operation with (l,r)=(1,3).\n * Perform the operation with (l,r)=(2,4).\n\n* * *"}, {"input": "5\n 3 1 2 3 1", "output": "5\n \n\n* * *"}, {"input": "8\n 4 23 75 0 23 96 50 100", "output": "221"}] |
Print the minimum number of watering operations required to satisfy the
condition.
* * * | s222243752 | Runtime Error | p03147 | Input is given from Standard Input in the following format:
N
h_1 h_2 h_3 ...... h_N | 多分再帰使うんだろうね
| Statement
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the
heights of all flowers are 0. You are given a sequence
h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of
Flower k to h_k for all k (1 \leq k \leq N), by repeating the following
"watering" operation:
* Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.
Find the minimum number of watering operations required to satisfy the
condition. | [{"input": "4\n 1 2 2 1", "output": "2\n \n\nThe minimum number of watering operations required is 2. One way to achieve it\nis:\n\n * Perform the operation with (l,r)=(1,3).\n * Perform the operation with (l,r)=(2,4).\n\n* * *"}, {"input": "5\n 3 1 2 3 1", "output": "5\n \n\n* * *"}, {"input": "8\n 4 23 75 0 23 96 50 100", "output": "221"}] |
Print the answer.
* * * | s675549387 | Runtime Error | p03517 | Input is given from Standard Input in the following format:
N M K
c_1 c_2 ... c_{N}
a_1 b_1 w_1
:
a_M b_M w_M | #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
cerr << endl;
rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
cerr << "INF";
}
else
cerr << v[i][j];
cerr << (j == v[i].size() - 1 ? '\n' : ' ');
}
cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
__int128 parse(string &s) {
__int128 ret = 0;
for (int i = 0; i < s.length(); i++)
if ('0' <= s[i] && s[i] <= '9')
ret = 10 * ret + s[i] - '0';
return ret;
}
*/
#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
using Weight = int;
using Flow = int;
struct Edge {
int s, d; Weight w; Flow c;
Edge() {};
Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;
void addArc(Graph &g, int s, int d, Weight w = 1) {
g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
addArc(g, a, b, w);
addArc(g, b, a, w);
}
struct DisjointSet {
// 2つのグループを1つにまとめる と 2つの要素が同じグループに所属しているかどうかを判定する
vector<int> rank, p, S; // p->parent S[findSet(v)] ->連結成分の大きさ
DisjointSet() {}
DisjointSet(int size) {
S.resize(size, 1);
rank.resize(size, 0);
p.resize(size, 0);
rep(i, 0, size) makeSet(i);
}
void makeSet(int x) {
p[x] = x;
rank[x] = 0;
}
bool same(int x, int y) { // 判定する
return findSet(x) == findSet(y);
}
void unite(int x, int y) { // 連結するときにはこれを使う
if (same(x, y))
return;
link(findSet(x), findSet(y));
}
void link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
}
else {
p[x] = y;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
S[x] = S[y] = S[x] + S[y];
}
int findSet(int x) {
if (x != p[x]) {
p[x] = findSet(p[x]); // path compression
}
return p[x];
}
int connectedComponentSize(int x) { return S[findSet(x)]; }
};
int kruskal(int N,int K, vector<Edge> &edges) {
int totalCost = 0;
sort(all(edges));
DisjointSet dset(N);
int k = 0;
rep(i, 0, edges.size()) {
Edge e = edges[i];
if (!dset.same(e.s, e.d)) {
totalCost += e.w;
dset.unite(e.s, e.d);
k++;
if (k == K - 1)break;
}
}
if (k != K - 1)totalCost = -1;
return totalCost;
}
signed main(signed argc, char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int N, M; cin >> N >> M;
int K; cin >> K;
vector<int>c(N);
int x = K;
rep(i, 0, N) {
cin >> c[i];
c[i]--;
if (c[i] == -1)c[i] = x++;
}
Edges es;
loop(M) {
int a, b, w; cin >> a >> b >> w;
a--, b--;
es.eb(c[a], c[b], w);
}
cout << kruskal(x,K, es) << endl;
return 0;
}
| Statement
Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges
numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of
w_i.
Now, he is in the middle of painting these N vertices in K colors numbered
1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in
which case Vertex i is not yet painted.
After he paints each vertex that is not yet painted in one of the K colors, he
will give G to Snuke.
Based on G, Snuke will make another undirected graph G' with K vertices
numbered 1,2,...,K and M edges. Initially, there is no edge in G'. The i-th
edge will be added as follows:
* Let x and y be the colors of the two vertices connected by Edge i in G.
* Add an edge of length w_i connecting Vertex x and y in G'.
What is the minimum possible sum of the lengths of the edges in the minimum
spanning tree of G'? If G' will not be connected regardless of how Ringo
paints the vertices, print -1. | [{"input": "4 3 3\n 1 0 1 2\n 1 2 10\n 2 3 20\n 2 4 50", "output": "60\n \n\nG' will only be connected when Vertex 2 is painted in Color 3.\n\n* * *"}, {"input": "5 2 4\n 0 0 0 0 0\n 1 2 10\n 2 3 10", "output": "-1\n \n\nRegardless of how Ringo paints the vertices, two edges is not enough to\nconnect four vertices as one.\n\n* * *"}, {"input": "9 12 9\n 1 2 3 4 5 6 7 8 9\n 6 9 9\n 8 9 6\n 6 7 85\n 9 5 545631016\n 2 1 321545\n 1 6 33562944\n 7 3 84946329\n 9 7 15926167\n 4 7 53386480\n 5 8 70476\n 4 6 4549\n 4 8 8", "output": "118901402\n \n\n* * *"}, {"input": "18 37 12\n 5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1\n 17 1 1\n 11 16 7575\n 11 15 9\n 10 10 289938980\n 5 10 17376\n 18 4 1866625\n 8 11 959154208\n 18 13 200\n 16 13 2\n 2 7 982223\n 12 12 9331\n 13 12 8861390\n 14 13 743\n 2 10 162440\n 2 4 981849\n 7 9 1\n 14 17 2800\n 2 7 7225452\n 3 7 85\n 5 17 4\n 2 13 1\n 10 3 45\n 1 15 973\n 14 7 56553306\n 16 17 70476\n 7 18 9\n 9 13 27911\n 18 14 7788322\n 11 11 8925\n 9 13 654295\n 2 10 9\n 10 1 545631016\n 3 4 5\n 17 12 1929\n 2 11 57\n 1 5 4\n 1 17 7807368", "output": "171"}] |
Print the answer.
* * * | s355087258 | Wrong Answer | p03517 | Input is given from Standard Input in the following format:
N M K
c_1 c_2 ... c_{N}
a_1 b_1 w_1
:
a_M b_M w_M | class Unionfindtree:
def __init__(self, number):
self.par = [i for i in range(number)]
self.rank = [0] * (number)
def find(self, x): # 親を探す
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y): # x,yを繋げる
px = self.find(x)
py = self.find(y)
if px == py:
return
if self.rank[px] < self.rank[py]:
self.par[px] = py
else:
self.par[py] = px
if self.rank[px] == self.rank[py]:
self.rank[px] += 1
def connect(self, x, y): # 親が同じかみる
return self.find(x) == self.find(y)
N, M, K = map(int, input().split())
C = [int(i) for i in input().split()]
table = []
t = K
dd = {}
for i in range(M):
s, u, c = map(int, input().split())
a, b = C[s - 1], C[u - 1]
if a == 0:
a = dd.get(s, -1)
if a == -1:
t += 1
dd[s] = t
a = t
elif b == 0:
b = dd.get(u, -1)
if b == -1:
t += 1
dd[u] = t
b = t
table.append((c, a, b))
tree = Unionfindtree(t + 1)
table.sort()
ct = K - 1
ans = 0
for c, a, b in table:
if not tree.connect(a, b) and ct > 0:
tree.union(a, b)
ans += c
ct -= 1
if ct > 0:
print(-1)
else:
print(ans)
| Statement
Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges
numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of
w_i.
Now, he is in the middle of painting these N vertices in K colors numbered
1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in
which case Vertex i is not yet painted.
After he paints each vertex that is not yet painted in one of the K colors, he
will give G to Snuke.
Based on G, Snuke will make another undirected graph G' with K vertices
numbered 1,2,...,K and M edges. Initially, there is no edge in G'. The i-th
edge will be added as follows:
* Let x and y be the colors of the two vertices connected by Edge i in G.
* Add an edge of length w_i connecting Vertex x and y in G'.
What is the minimum possible sum of the lengths of the edges in the minimum
spanning tree of G'? If G' will not be connected regardless of how Ringo
paints the vertices, print -1. | [{"input": "4 3 3\n 1 0 1 2\n 1 2 10\n 2 3 20\n 2 4 50", "output": "60\n \n\nG' will only be connected when Vertex 2 is painted in Color 3.\n\n* * *"}, {"input": "5 2 4\n 0 0 0 0 0\n 1 2 10\n 2 3 10", "output": "-1\n \n\nRegardless of how Ringo paints the vertices, two edges is not enough to\nconnect four vertices as one.\n\n* * *"}, {"input": "9 12 9\n 1 2 3 4 5 6 7 8 9\n 6 9 9\n 8 9 6\n 6 7 85\n 9 5 545631016\n 2 1 321545\n 1 6 33562944\n 7 3 84946329\n 9 7 15926167\n 4 7 53386480\n 5 8 70476\n 4 6 4549\n 4 8 8", "output": "118901402\n \n\n* * *"}, {"input": "18 37 12\n 5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1\n 17 1 1\n 11 16 7575\n 11 15 9\n 10 10 289938980\n 5 10 17376\n 18 4 1866625\n 8 11 959154208\n 18 13 200\n 16 13 2\n 2 7 982223\n 12 12 9331\n 13 12 8861390\n 14 13 743\n 2 10 162440\n 2 4 981849\n 7 9 1\n 14 17 2800\n 2 7 7225452\n 3 7 85\n 5 17 4\n 2 13 1\n 10 3 45\n 1 15 973\n 14 7 56553306\n 16 17 70476\n 7 18 9\n 9 13 27911\n 18 14 7788322\n 11 11 8925\n 9 13 654295\n 2 10 9\n 10 1 545631016\n 3 4 5\n 17 12 1929\n 2 11 57\n 1 5 4\n 1 17 7807368", "output": "171"}] |
For each dataset, print "YES" or "NO" in a line. | s745118784 | Wrong Answer | p00012 | Input consists of several datasets. Each dataset consists of:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_p$ $y_p$
All the input are real numbers. Input ends with EOF. The number of datasets is
less than or equal to 100. | while True:
try:
x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
if xp < 0 or yp < 0:
print("No")
else:
print("Yes")
except:
break
| A Point in a Triangle
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3,
y_3)$ on a plain.
Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the
triangle and "NO" if not. | [{"input": ".0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n 0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0", "output": "YES\n NO"}] |
For each dataset, print "YES" or "NO" in a line. | s074741759 | Accepted | p00012 | Input consists of several datasets. Each dataset consists of:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_p$ $y_p$
All the input are real numbers. Input ends with EOF. The number of datasets is
less than or equal to 100. | import math
PI = math.pi
EPS = 10**-10
def edge(a, b):
return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5
def area(a, b, c):
s = (a + b + c) / 2
return (s * (s - a) * (s - b) * (s - c)) ** 0.5
def LawOfCosines(a, b, c): # 余弦定理
return math.acos((b * b + c * c - a * a) / (2.0 * b * c))
def is_same(x, y):
return abs(x - y) < EPS
class Triangle:
def __init__(self, p):
a, b, c = p
self.a = a
self.b = b
self.c = c
self.edgeA = edge(b, c)
self.edgeB = edge(c, a)
self.edgeC = edge(a, b)
self.area = area(self.edgeA, self.edgeB, self.edgeC)
self.angleA = LawOfCosines(self.edgeA, self.edgeB, self.edgeC)
self.angleB = LawOfCosines(self.edgeB, self.edgeC, self.edgeA)
self.angleC = LawOfCosines(self.edgeC, self.edgeA, self.edgeB)
def circumscribeadCircleRadius(self): # 外接円の半径を返す
return self.edgeA / math.sin(self.angleA) / 2.0
def circumscribedCircleCenter(self): # 外接円の中心の座標を返す
a = math.sin(2.0 * self.angleA)
b = math.sin(2.0 * self.angleB)
c = math.sin(2.0 * self.angleC)
X = (self.a[0] * a + self.b[0] * b + self.c[0] * c) / (a + b + c)
Y = (self.a[1] * a + self.b[1] * b + self.c[1] * c) / (a + b + c)
return X, Y
def inscribedCircleRadius(self): # 内接円の半径
return 2 * self.area / (self.edgeA + self.edgeB + self.edgeC)
def inscribedCircleCenter(self): # 内接円の中心の座標
points = [self.a, self.b, self.c]
edges = [self.edgeA, self.edgeB, self.edgeC]
s = sum(edges)
return [sum([points[j][i] * edges[j] for j in range(3)]) / s for i in range(2)]
def isInner(self, p): # 点が三角形の内側か判定
cross = lambda a, b: a[0] * b[1] - a[1] * b[0]
c1 = 0
c2 = 0
points = [self.a, self.b, self.c]
for i in range(3):
a = [
points[i][0] - points[(i + 1) % 3][0],
points[i][1] - points[(i + 1) % 3][1],
]
b = [points[i][0] - p[0], points[i][1] - p[1]]
c = cross(a, b)
if c > 0:
c1 += 1
elif c < 0:
c2 += 1
if c1 == 3 or c2 == 3:
return True
else:
return c1 + c2 != 3 and (c1 == 0 or c2 == 0)
if __name__ == "__main__":
while True:
try:
c = list(map(float, input().split()))
points = [(c[i], c[i + 1]) for i in range(0, 6, 2)]
point = [c[6], c[7]]
t = Triangle(points)
print(["NO", "YES"][t.isInner(point)])
except:
break
| A Point in a Triangle
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3,
y_3)$ on a plain.
Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the
triangle and "NO" if not. | [{"input": ".0 0.0 2.0 0.0 2.0 2.0 1.5 0.5\n 0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0", "output": "YES\n NO"}] |
Print the number of the different ways Snuke can make a serving of Skewer
Meal, modulo 10^9+7.
* * * | s857122274 | Wrong Answer | p04051 | The input is given from Standard Input in the following format:
N
A_1 B_1
A_2 B_2
:
A_N B_N | import sys
from collections import defaultdict
import numpy as np
def prepare(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
n = int(sys.stdin.buffer.readline())
mp = map(int, sys.stdin.buffer.read().split())
ab = list(zip(mp, mp))
atob = defaultdict(list)
max_a, max_b = 0, 0
for a, b in ab:
atob[a].append(b)
max_a = max(max_a, a)
max_b = max(max_b, b)
MOD = 10**9 + 7
dp = np.zeros(max_b * 2 + 1, dtype=np.int64)
ans = 0
for i in range(-max_a, max_a + 1):
if i < 0 and -i in atob:
for j in atob[-i]:
dp[-j + max_b] += 1
dp = np.add.accumulate(dp) % MOD
if i > 0 and i in atob:
for j in atob[i]:
ans = (ans + dp[j + max_b]) % MOD
facts, invs = prepare(2 * (max_a + max_b), MOD)
ans = int(ans)
for a, b in ab:
ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD
print(ans // 2)
| Statement
Snuke is having another barbeque party.
This time, he will make one serving of _Skewer Meal_.
He has a stock of N _Skewer Meal Packs_. The i-th Skewer Meal Pack contains
one skewer, A_i pieces of beef and B_i pieces of green pepper. All skewers in
these packs are different and distinguishable, while all pieces of beef and
all pieces of green pepper are, respectively, indistinguishable.
To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out
all of the contents from the chosen packs, that is, two skewers and some
pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be
used.) Then, all those pieces of food are threaded onto both skewers, one by
one, in any order.
(See the image in the Sample section for better understanding.)
In how many different ways can he make a Skewer Meal? Two ways of making a
Skewer Meal is different if and only if the sets of the used skewers are
different, or the orders of the pieces of food are different. Since this
number can be extremely large, find it modulo 10^9+7. | [{"input": "3\n 1 1\n 1 1\n 2 1", "output": "26\n \n\nThe 26 ways of making a Skewer Meal are shown below. Gray bars represent\nskewers, each with a number denoting the Skewer Meal Set that contained the\nskewer. Brown and green rectangles represent pieces of beef and green pepper,\nrespectively.\n\n"}] |
Print the sum of the health points restored from eating two takoyaki over all
possible choices of two takoyaki from the N takoyaki served.
* * * | s823606041 | Wrong Answer | p02886 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | N = int(input().strip())
d = list(map(int, input().strip().split()))
sum_ = 0
for i, x in enumerate(d):
for y in d[i + 1 :]:
print(x, y)
sum_ += x * y
print(sum_)
| Statement
It's now the season of TAKOYAKI FESTIVAL!
This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will
be served. The _deliciousness_ of the i-th takoyaki is d_i.
As is commonly known, when you eat two takoyaki of deliciousness x and y
together, you restore x \times y health points.
There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki
served in the festival. For each of these choices, find the health points
restored from eating the two takoyaki, then compute the sum of these \frac{N
\times (N - 1)}{2} values. | [{"input": "3\n 3 1 2", "output": "11\n \n\nThere are three possible choices:\n\n * Eat the first and second takoyaki. You will restore 3 health points.\n * Eat the second and third takoyaki. You will restore 2 health points.\n * Eat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\n* * *"}, {"input": "7\n 5 0 7 8 3 3 2", "output": "312"}] |
Print the sum of the health points restored from eating two takoyaki over all
possible choices of two takoyaki from the N takoyaki served.
* * * | s406173274 | Accepted | p02886 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | n, *d = map(int, open(0).read().split())
s = sum(d) ** 2
for v in d:
s -= v**2
print("%d" % (s / 2))
| Statement
It's now the season of TAKOYAKI FESTIVAL!
This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will
be served. The _deliciousness_ of the i-th takoyaki is d_i.
As is commonly known, when you eat two takoyaki of deliciousness x and y
together, you restore x \times y health points.
There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki
served in the festival. For each of these choices, find the health points
restored from eating the two takoyaki, then compute the sum of these \frac{N
\times (N - 1)}{2} values. | [{"input": "3\n 3 1 2", "output": "11\n \n\nThere are three possible choices:\n\n * Eat the first and second takoyaki. You will restore 3 health points.\n * Eat the second and third takoyaki. You will restore 2 health points.\n * Eat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\n* * *"}, {"input": "7\n 5 0 7 8 3 3 2", "output": "312"}] |
Print the sum of the health points restored from eating two takoyaki over all
possible choices of two takoyaki from the N takoyaki served.
* * * | s743000376 | Runtime Error | p02886 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | a, b = map(int, input().split())
if 1 <= a <= 9 or 1 <= b <= 9:
print(b)
else:
print(0)
| Statement
It's now the season of TAKOYAKI FESTIVAL!
This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will
be served. The _deliciousness_ of the i-th takoyaki is d_i.
As is commonly known, when you eat two takoyaki of deliciousness x and y
together, you restore x \times y health points.
There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki
served in the festival. For each of these choices, find the health points
restored from eating the two takoyaki, then compute the sum of these \frac{N
\times (N - 1)}{2} values. | [{"input": "3\n 3 1 2", "output": "11\n \n\nThere are three possible choices:\n\n * Eat the first and second takoyaki. You will restore 3 health points.\n * Eat the second and third takoyaki. You will restore 2 health points.\n * Eat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\n* * *"}, {"input": "7\n 5 0 7 8 3 3 2", "output": "312"}] |
Print the sum of the health points restored from eating two takoyaki over all
possible choices of two takoyaki from the N takoyaki served.
* * * | s743408859 | Accepted | p02886 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | # -*- coding: utf-8 -*-
import sys
from itertools import combinations
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N = MAP()
A = LIST()
ans = 0
for a, b in combinations(A, 2):
ans += a * b
print(ans)
| Statement
It's now the season of TAKOYAKI FESTIVAL!
This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will
be served. The _deliciousness_ of the i-th takoyaki is d_i.
As is commonly known, when you eat two takoyaki of deliciousness x and y
together, you restore x \times y health points.
There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki
served in the festival. For each of these choices, find the health points
restored from eating the two takoyaki, then compute the sum of these \frac{N
\times (N - 1)}{2} values. | [{"input": "3\n 3 1 2", "output": "11\n \n\nThere are three possible choices:\n\n * Eat the first and second takoyaki. You will restore 3 health points.\n * Eat the second and third takoyaki. You will restore 2 health points.\n * Eat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\n* * *"}, {"input": "7\n 5 0 7 8 3 3 2", "output": "312"}] |
Print the sum of the health points restored from eating two takoyaki over all
possible choices of two takoyaki from the N takoyaki served.
* * * | s080142387 | Accepted | p02886 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | def solve():
data = read()
result = think(data)
write(result)
def read():
n = read_int(1)[0]
return read_int(n)
def read_int(n):
return list(map(lambda x: int(x), read_line().split(" ")))[:n]
def read_float(n):
return list(map(lambda x: float(x), read_line().split(" ")))[:n]
def read_line(n=0):
if n == 0:
return input().rstrip()
else:
return input().rstrip()[:n]
def think(data):
n = len(data)
total = 0
for i in range(n):
for j in range(i + 1, n):
total += data[i] * data[j]
return total
def write(result):
print(result)
if __name__ == "__main__":
# import doctest
# doctest.testmod()
# import sys
# sys.setrecursionlimit(10000)
solve()
| Statement
It's now the season of TAKOYAKI FESTIVAL!
This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will
be served. The _deliciousness_ of the i-th takoyaki is d_i.
As is commonly known, when you eat two takoyaki of deliciousness x and y
together, you restore x \times y health points.
There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki
served in the festival. For each of these choices, find the health points
restored from eating the two takoyaki, then compute the sum of these \frac{N
\times (N - 1)}{2} values. | [{"input": "3\n 3 1 2", "output": "11\n \n\nThere are three possible choices:\n\n * Eat the first and second takoyaki. You will restore 3 health points.\n * Eat the second and third takoyaki. You will restore 2 health points.\n * Eat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\n* * *"}, {"input": "7\n 5 0 7 8 3 3 2", "output": "312"}] |
Print the sum of the health points restored from eating two takoyaki over all
possible choices of two takoyaki from the N takoyaki served.
* * * | s162411848 | Accepted | p02886 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | _, d = open(0)
(*d,) = map(int, d.split())
print(sum(d) ** 2 - sum(i**2 for i in d) >> 1)
| Statement
It's now the season of TAKOYAKI FESTIVAL!
This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will
be served. The _deliciousness_ of the i-th takoyaki is d_i.
As is commonly known, when you eat two takoyaki of deliciousness x and y
together, you restore x \times y health points.
There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki
served in the festival. For each of these choices, find the health points
restored from eating the two takoyaki, then compute the sum of these \frac{N
\times (N - 1)}{2} values. | [{"input": "3\n 3 1 2", "output": "11\n \n\nThere are three possible choices:\n\n * Eat the first and second takoyaki. You will restore 3 health points.\n * Eat the second and third takoyaki. You will restore 2 health points.\n * Eat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\n* * *"}, {"input": "7\n 5 0 7 8 3 3 2", "output": "312"}] |
Print the sum of the health points restored from eating two takoyaki over all
possible choices of two takoyaki from the N takoyaki served.
* * * | s136574877 | Accepted | p02886 | Input is given from Standard Input in the following format:
N
d_1 d_2 ... d_N | # coding: utf-8
yaki_num = int(input())
oisisa = list(int(i) for i in input().split())
hp = 0
for i in range(yaki_num):
for j in range(i + 1, yaki_num):
hp += oisisa[i] * oisisa[j]
print(hp)
| Statement
It's now the season of TAKOYAKI FESTIVAL!
This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will
be served. The _deliciousness_ of the i-th takoyaki is d_i.
As is commonly known, when you eat two takoyaki of deliciousness x and y
together, you restore x \times y health points.
There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki
served in the festival. For each of these choices, find the health points
restored from eating the two takoyaki, then compute the sum of these \frac{N
\times (N - 1)}{2} values. | [{"input": "3\n 3 1 2", "output": "11\n \n\nThere are three possible choices:\n\n * Eat the first and second takoyaki. You will restore 3 health points.\n * Eat the second and third takoyaki. You will restore 2 health points.\n * Eat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\n* * *"}, {"input": "7\n 5 0 7 8 3 3 2", "output": "312"}] |
Print the count.
* * * | s501485560 | Wrong Answer | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
l = [3, 5, 7, 11, 13]
ans = [0] * 10000
for i in range(3):
for j in range(1, 4):
for k in range(2, 5):
ans[l[i] * l[j] * l[k]] = 1
ans[135] = 1
ans[189] = 1
print(sum(ans[: n + 1]))
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s655676680 | Accepted | p03281 | Input is given from Standard Input in the following format:
N | N = int(input())
lis = [i for i in range(2, N + 1) if i % 2 == 1]
ans2 = 0
check = 0
for one in lis:
Prime = []
count = []
t = 0
ans1 = 1
for k in range(2, one + 1):
while (one % k) == 0:
one //= k
if k in Prime:
count[Prime.index(k)] += 1
else:
Prime.append(k)
count.append(1)
t += 1
for j in range(0, t):
ans1 *= count[j] + 1
if ans1 == 8:
ans2 += 1
print(ans2)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s847583059 | Wrong Answer | p03281 | Input is given from Standard Input in the following format:
N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def inputI():
return int(input().strip())
def inputS():
return input().strip()
def inputIL():
return list(map(int, input().split()))
def inputSL():
return list(map(str, input().split()))
def inputILs(n):
return list(int(input()) for _ in range(n))
def inputSLs(n):
return list(input().strip() for _ in range(n))
def inputILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def Yes():
print("Yes")
return
def No():
print("No")
return
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def Base_10_to_n(X, n):
if int(X / n):
return Base_10_to_n(int(X / n), n) + [X % n]
return [X % n]
#############
# Main Code #
#############
N = inputI()
ans = 0
for i in range(2, N + 1):
if len(make_divisors(i)) == 8:
ans += 1
print(ans)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s889372164 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
ans = 0
for val in range(n):
if len(factorization(val)) == 8:
ans +=1
print(ans) | Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s247559894 | Accepted | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
print(
len(
[
i
for i in range(1, n + 1)
if i % 2 == 1 and len([1 for x in range(1, i + 1) if i % x == 0]) == 8
]
)
)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s031599722 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
ans = 0
cnt = 0
for i in range(1,n+1):
for j in range(1,n+1):
if i%j = 0:
ans += 1
if ans = 8:
cnt += 1
print(cnt)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s077249557 | Wrong Answer | p03281 | Input is given from Standard Input in the following format:
N | print(1 if int(input()) > 104 else 0)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s934782141 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | N = int(input())
if N < 105:
print(0)
elif N < 135:
print(1)
elif N < 165:
print(2)
elif N < 188
print(3)
elif N < 195:
print(4)
else:
print(5) | Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s404416666 | Wrong Answer | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
l = [i for i in range(1, n + 1) if i % 2 == 1]
print(l)
cnt = 0
for w in l:
i = w
fct = []
b, e = 3, 0
while b * b < w:
while i % b == 0:
i = i // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if i > 1:
fct.append((i, 1))
if len(fct) > 1:
r = 1
for j in fct:
r = r * (j[1] + 1)
elif len(fct) == 1:
r = fct[0][1] + 1
else:
r = 0
if r == 8:
cnt += 1
print(cnt)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s804661098 | Wrong Answer | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
l = list(range(1, n + 1))
k = [27, 105, 125, 165, 195]
lk = set(l) & set(k)
print(len(lk))
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s545236355 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | N=int(input())
ans=0
odd=[]
for i in range(1,N+1):
if i%2!=0:
odd.append(i)
if N <104:
pass
elif N=105:
ans=1
else:
ans=1
for i in range(106,N+1):
if i%2 !=0:
tmp=0
for j in odd:
if i%j==0:
tmp=+1
if tmp==8:
ans+=1
print(ans) | Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s020289325 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | N = int(input())
cnt = 0
for i in range(1, N + 1):
k = 0
for j in range(1, N + 1):
if i % j == 0:
k += 1
if k == 8:
cnt += 1
print(cnt)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s135527696 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
if n = 105:
print(1)
else:
print(0) | Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s147647733 | Accepted | p03281 | Input is given from Standard Input in the following format:
N | def Div(N):
L = []
R = []
I = 1
while I * I <= N:
if N % I == 0:
L.append(I)
if I != (N // I):
R.append(N // I)
I += 1
return L + R[::-1]
N = int(input())
Count = 0
for T in range(1, N + 1, 2):
if len(Div(T)) == 8:
Count += 1
print(Count)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s850383388 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
ret = 0
for j in range(1,n+1):
cnt = 0
if j % 2 = 1:
for i in range(1,j+1):
if n % i == 0:
cnt += 1
if cnt == 8:
ret += 1
print(ret) | Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s641503387 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
ans = 0
for j in range(1,n+1):
count = 1
for i in range(n//2):
if n % i == 0:
count += 1
if count >= 8:
ans +=1
print(ans)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s319706567 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | N, = list(map(int,input().split()))
ans = 0
for i in range(N):
num = 0
for j in range(200):
if N % j == 0:
num += 1
if num == 8:
ans += 1
print(ans)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s518703803 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | N=in(input())
conut=0
for i in range(1,N+1):
a=[]
if i%2==0:
continue
for j in range(1,i+1):
if i%j==0:
a.append(j)
if len(a)==8:
count+=1
print(count) | Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s209268768 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
l = [i for i in range(1, n + 1) if i % 2 == 1]
print(l)
cnt = 0
for w in l:
i = w
fct = []
b, e = 3, 0
while b * b < w:
while i % b == 0:
i = i // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if i > 1:
fct.append((i, 1))
if len(fct) > 1:
r = 1
for j in fct:
r = r * (j[1] + 1)
elif len(fct) == 1:
r = fct[0][1] + 1
else:
r = 0
if r == 8:
print(w, fct, r)
cnt += 1
print(cnt) | Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s668151397 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | n=int(input())
if n<105:
print(0)
if (n>=105)and(n<165):
print(1)
else:
print(2) | Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s012476904 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | n=int(input())
elif n<105:
print(0)
elif n<135:
print(1)
elif n<165:
print(2)
else:
print(3)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s846952908 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | N=int(input())
num=0
for j in range(1,N+1,2):
cnt=0
for i in range(1,j+1):
# print(i)
# print(j)
if j%i==0 :
cnt=cnt+1
if cnt==8 :
# print(cnt)
num+=1
# print("---")
print(num)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s021636997 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | N = int(input())
count1 = 0
for i in range(1,N+1):
if i % 2 != 0:
count2 = 0
for j in range(1,i+1):
if i % j == 0:
count2 += 1
if count2 == 8:
count1 += 1
print(count1)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s659687230 | Accepted | p03281 | Input is given from Standard Input in the following format:
N | def factorization(n):
def factor_sub(n, m):
c = 0
while n % m == 0:
c += 1
n /= m
return c, n
#
buff = []
c, m = factor_sub(n, 2)
if c > 0:
buff.append((2, c))
c, m = factor_sub(m, 3)
if c > 0:
buff.append((3, c))
x = 5
while m >= x * x:
c, m = factor_sub(m, x)
if c > 0:
buff.append((x, c))
if x % 6 == 5:
x += 2
else:
x += 4
if m > 1:
buff.append((m, 1))
return buff
def divisor_num(n):
a = 1
for _, x in factorization(n):
a *= x + 1
return a
n = int(input())
cnt = 0
for x in range(n + 1):
if x % 2 == 1:
if divisor_num(x) == 8:
cnt += 1
print(cnt)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s553829153 | Accepted | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
l = list([105, 135, 165, 189, 195])
a = l.count(n)
l.append(n)
l.sort()
print(l.index(n) + a)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s101936862 | Wrong Answer | p03281 | Input is given from Standard Input in the following format:
N | n = int(input())
a = [3, 5, 7, 11, 13]
s = {
a[i] * a[j] * a[k]
for i in range(len(a) - 2)
for j in range(i + 1, len(a) - 1)
for k in range(j + 1, len(a))
if a[i] * a[j] * a[k] <= n
}
print(len(s))
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s105333362 | Runtime Error | p03281 | Input is given from Standard Input in the following format:
N | print(int(__file__[5]) / 2)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
Print the count.
* * * | s425163804 | Wrong Answer | p03281 | Input is given from Standard Input in the following format:
N | N = int(input()) + 1
yakusuu = 0
for i in range(1, int((N - N % 2) / 2) + 2):
cnt = 0
ii = 1 + 2 * (i - 2)
for j in range(1, ii):
if ii % j == 0:
cnt = cnt + 1
cnt = cnt + 1
print(str(ii) + "の約数は" + str(cnt) + "個")
if cnt == 8:
yakusuu = yakusuu + 1
print(yakusuu)
| Statement
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive
divisors are there between 1 and N (inclusive)? | [{"input": "105", "output": "1\n \n\nAmong the numbers between 1 and 105, the only number that is odd and has\nexactly eight divisors is 105.\n\n* * *"}, {"input": "7", "output": "0\n \n\n1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there\nis no number that satisfies the condition."}] |
If it is impossible to partition the integers satisfying the condition, print
`-1`. If it is possible, print N triples in the following format:
a_1 b_1 c_1
:
a_N b_N c_N
* * * | s995913226 | Accepted | p02869 | Input is given from Standard Input in the following format:
N K | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N, K = map(int, read().split())
def solve_even(N, K):
L = N // 2
x = np.arange(K, K + N)
y = np.concatenate(
[np.arange(K + L + N, K + L + N + L), np.arange(K + N, K + L + N)]
)
add = N - (K + L)
z = x + y + add
z[L:] += 1
answer = np.vstack([x, y, z]).T
print("\n".join(" ".join(row) for row in answer.astype(str)))
def solve_odd(N, K):
L = N // 2
x = np.arange(K, K + N)
y = np.concatenate(
[np.arange(K + L + N, K + L + N + L + 1), np.arange(K + N, K + L + N)]
)
add = N - (K + L)
z = x + y + add
answer = np.vstack([x, y, z]).T
print("\n".join(" ".join(row) for row in answer.astype(str)))
def solve(N, K):
if K + K > N + 1:
print(-1)
return
if N & 1:
solve_odd(N, K)
else:
solve_even(N, K)
solve(N, K)
| Statement
Given are positive integers N and K.
Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N
triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is
satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one
of those triples.
* For every integer i from 1 to N, a_i + b_i \leq c_i holds.
If the answer is yes, construct one such partition. | [{"input": "1 1", "output": "1 2 3\n \n\n* * *"}, {"input": "3 3", "output": "-1"}] |
If it is impossible to partition the integers satisfying the condition, print
`-1`. If it is possible, print N triples in the following format:
a_1 b_1 c_1
:
a_N b_N c_N
* * * | s453631559 | Runtime Error | p02869 | Input is given from Standard Input in the following format:
N K | import numpy as np
n, m = map(int, input().split())
ro = [[0 for i in range(n)] for i in range(n)]
lis = np.array([[int(i) for i in input().split(" ")] for i in range(m)])
lis = lis[lis[:, 0].argsort(), :]
for i in lis:
l, r, c = i
for j in range(i[0] - 1, i[1] - 1):
for k in range(i[0], i[1]):
if ro[j][k] == 0:
ro[j][k] = i[2]
ro[k][j] = i[2]
else:
if ro[j][k] > i[2]:
ro[j][k] = i[2]
ro[k][j] = i[2]
route_list = ro
node_num = len(route_list) # ノードの数
unsearched_nodes = list(range(node_num)) # 未探索ノード
distance = [float("inf")] * node_num # ノードごとの距離のリスト
previous_nodes = [
-1
] * node_num # 最短経路でそのノードのひとつ前に到達するノードのリスト
distance[0] = 0 # 初期のノードの距離は0とする
def get_target_min_index(min_index, distance, unsearched_nodes):
start = 0
while True:
index = distance.index(min_index, start)
found = index in unsearched_nodes
if found:
return index
else:
start = index + 1
while len(unsearched_nodes) != 0: # 未探索ノードがなくなるまで繰り返す
# まず未探索ノードのうちdistanceが最小のものを選択する
posible_min_distance = float(
"inf"
) # 最小のdistanceを見つけるための一時的なdistance。初期値は inf に設定。
for node_index in unsearched_nodes: # 未探索のノードのループ
if posible_min_distance > distance[node_index]:
posible_min_distance = distance[node_index] # より小さい値が見つかれば更新
target_min_index = get_target_min_index(
posible_min_distance, distance, unsearched_nodes
) # 未探索ノードのうちで最小のindex番号を取得
unsearched_nodes.remove(target_min_index) # ここで探索するので未探索リストから除去
target_edge = route_list[
target_min_index
] # ターゲットになるノードからのびるエッジのリスト
for index, route_dis in enumerate(target_edge):
if route_dis != 0:
if distance[index] > (distance[target_min_index] + route_dis):
distance[index] = (
distance[target_min_index] + route_dis
) # 過去に設定されたdistanceよりも小さい場合はdistanceを更新
previous_nodes[index] = (
target_min_index # ひとつ前に到達するノードのリストも更新
)
if distance[node_num - 1] == float("inf"):
print(-1)
else:
print(distance[node_num - 1])
| Statement
Given are positive integers N and K.
Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N
triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is
satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one
of those triples.
* For every integer i from 1 to N, a_i + b_i \leq c_i holds.
If the answer is yes, construct one such partition. | [{"input": "1 1", "output": "1 2 3\n \n\n* * *"}, {"input": "3 3", "output": "-1"}] |
If it is impossible to partition the integers satisfying the condition, print
`-1`. If it is possible, print N triples in the following format:
a_1 b_1 c_1
:
a_N b_N c_N
* * * | s408972014 | Wrong Answer | p02869 | Input is given from Standard Input in the following format:
N K | from random import random
class TreapNode:
def __init__(self, val):
self.val = val
self.priority = random()
self.parent = None
self.right = None
self.left = None
class Treap:
def __init__(self, is_multiset=False):
self.root = None
self.is_multiset = is_multiset
def search(self, val: int) -> bool:
ptr = self.root
while ptr is not None:
if ptr.val == val:
return True
if val < ptr.val:
ptr = ptr.left
else:
ptr = ptr.right
return False
def insert(self, val: int):
if self.root is None:
self.root = TreapNode(val)
return
ptr = self.root
while True:
if val < ptr.val:
if ptr.left is None:
ptr.left = TreapNode(val)
ptr.left.parent = ptr
ptr = ptr.left
break
ptr = ptr.left
else:
if val == ptr.val and not self.is_multiset:
return
if ptr.right is None:
ptr.right = TreapNode(val)
ptr.right.parent = ptr
ptr = ptr.right
break
ptr = ptr.right
while (ptr.parent is not None) and (ptr.parent.priority > ptr.priority):
if ptr.parent.right == ptr:
self.rotate_left(ptr.parent)
else:
self.rotate_right(ptr.parent)
if ptr.parent is None:
self.root = ptr
def delete(self, val: int):
if self.root is None:
return
ptr = self.root
while True:
if ptr is None:
return
if ptr.val == val:
break
elif val < ptr.val:
ptr = ptr.left
else:
ptr = ptr.right
while (ptr.left is not None) or (ptr.right is not None):
if ptr.left is None:
self.rotate_left(ptr)
elif ptr.right is None:
self.rotate_right(ptr)
elif ptr.left.priority < ptr.right.priority:
self.rotate_right(ptr)
else:
self.rotate_left(ptr)
if self.root == ptr:
self.root = ptr.parent
if ptr.left is None and ptr.right is None:
if ptr == self.root:
self.root = None
elif ptr.parent.left == ptr:
ptr.parent.left = None
else:
ptr.parent.right = None
def search_min(self, ptr):
while True:
if ptr.left is None:
return ptr
ptr = ptr.left
return ptr
def search_max(self):
ptr = self.root
while True:
if ptr.right is None:
return ptr.val
ptr = ptr.right
def rotate_left(self, ptr):
w = ptr.right
w.parent = ptr.parent
if w.parent is not None:
if w.parent.left == ptr:
w.parent.left = w
else:
w.parent.right = w
ptr.right = w.left
if ptr.right is not None:
ptr.right.parent = ptr
ptr.parent = w
w.left = ptr
if ptr == self.root:
self.root = w
self.root.parent = None
def rotate_right(self, ptr):
w = ptr.left
w.parent = ptr.parent
if w.parent is not None:
if w.parent.right == ptr:
w.parent.right = w
else:
w.parent.left = w
ptr.left = w.right
if ptr.left is not None:
ptr.left.parent = ptr
ptr.parent = w
w.right = ptr
if ptr == self.root:
self.root = w
self.root.parent = None
def search_less_than(self, val):
if val == None:
return None
ptr = self.root
ret = None
while ptr is not None:
if ptr.val == val:
return ptr.val
elif ptr.val < val:
ret = ptr.val
ptr = ptr.right
else:
ptr = ptr.left
return ret
n, k = map(int, input().split())
tp = Treap()
for i in range(2 * n):
tp.insert(k + i)
ans = []
for i in range(n)[::-1]:
right = k + 2 * n + i
left1 = tp.search_max()
tp.delete(left1)
left2 = tp.search_less_than(right - left1)
if left2 is None:
print(-1)
exit()
tp.delete(left2)
ans.append((left1, left2, right))
for i in ans:
print(*i)
| Statement
Given are positive integers N and K.
Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N
triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is
satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one
of those triples.
* For every integer i from 1 to N, a_i + b_i \leq c_i holds.
If the answer is yes, construct one such partition. | [{"input": "1 1", "output": "1 2 3\n \n\n* * *"}, {"input": "3 3", "output": "-1"}] |
If it is impossible to partition the integers satisfying the condition, print
`-1`. If it is possible, print N triples in the following format:
a_1 b_1 c_1
:
a_N b_N c_N
* * * | s691239016 | Wrong Answer | p02869 | Input is given from Standard Input in the following format:
N K | import sys
readline = sys.stdin.readline
from itertools import accumulate
from collections import Counter
from bisect import bisect as br, bisect_left as bl
class PMS:
# 1-indexed
def __init__(self, A, B, issum=False):
# Aに初期状態の要素をすべて入れる,Bは値域のリスト
self.X, self.comp = self.compress(B)
self.size = len(self.X)
self.tree = [0] * (self.size + 1)
self.p = 2 ** (self.size.bit_length() - 1)
self.dep = self.size.bit_length()
CA = Counter(A)
S = [0] + list(accumulate([CA[self.X[i]] for i in range(self.size)]))
for i in range(1, 1 + self.size):
self.tree[i] = S[i] - S[i - (i & -i)]
if issum:
self.sumtree = [0] * (self.size + 1)
Ssum = [0] + list(
accumulate([CA[self.X[i]] * self.X[i] for i in range(self.size)])
)
for i in range(1, 1 + self.size):
self.sumtree[i] = Ssum[i] - Ssum[i - (i & -i)]
def compress(self, L):
# 座圧
L2 = list(set(L))
L2.sort()
C = {v: k for k, v in enumerate(L2, 1)}
# 1-indexed
return L2, C
def leng(self):
# 今入っている個数を取得
return self.count(self.X[-1])
def count(self, v):
# v(Bの元)以下の個数を取得
i = self.comp[v]
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def less(self, v):
# v(Bの元である必要はない)未満の個数を取得
i = bl(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def leq(self, v):
# v(Bの元である必要はない)以下の個数を取得
i = br(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, v, x):
# vをx個入れる,負のxで取り出す,iの個数以上取り出すとエラーを出さずにバグる
i = self.comp[v]
while i <= self.size:
self.tree[i] += x
i += i & -i
def get(self, i):
# i番目の値を取得
if i <= 0:
return -1
s = 0
k = self.p
for _ in range(self.dep):
if s + k <= self.size and self.tree[s + k] < i:
s += k
i -= self.tree[s]
k //= 2
return self.X[s]
def gets(self, v):
# 累積和がv以下となる最大のindexを返す
v1 = v
s = 0
k = self.p
for _ in range(self.dep):
if s + k <= self.size and self.sumtree[s + k] < v:
s += k
v -= self.sumtree[s]
k //= 2
if s == self.size:
return self.leng()
return self.count(self.X[s]) + (v1 - self.countsum(self.X[s])) // self.X[s]
def addsum(self, i, x):
# sumを扱いたいときにaddの代わりに使う
self.add(i, x)
x *= i
i = self.comp[i]
while i <= self.size:
self.sumtree[i] += x
i += i & -i
def countsum(self, v):
# v(Bの元)以下のsumを取得
i = self.comp[v]
s = 0
while i > 0:
s += self.sumtree[i]
i -= i & -i
return s
def getsum(self, i):
# i番目までのsumを取得
x = self.get(i)
return self.countsum(x) - x * (self.count(x) - i)
N, K = map(int, readline().split())
C = list(range(K + 2 * N, K + 3 * N))
Ans = []
abl = list(range(K, K + 2 * N))
AB = PMS(abl, abl)
ans = -1
for i in range(N):
c = C[N - 1 - i]
bx = AB.get(2 * N - 2 * i)
AB.add(bx, -1)
if c < bx:
break
bn = c - bx
k = AB.leq(bn)
if k == 0:
break
a = AB.get(k)
b = bx
AB.add(a, -1)
Ans.append((a, b, c))
else:
print("\n".join("{} {} {}".format(*a) for a in Ans))
ans = 1
if ans == -1:
print(ans)
| Statement
Given are positive integers N and K.
Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N
triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is
satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one
of those triples.
* For every integer i from 1 to N, a_i + b_i \leq c_i holds.
If the answer is yes, construct one such partition. | [{"input": "1 1", "output": "1 2 3\n \n\n* * *"}, {"input": "3 3", "output": "-1"}] |
If it is impossible to partition the integers satisfying the condition, print
`-1`. If it is possible, print N triples in the following format:
a_1 b_1 c_1
:
a_N b_N c_N
* * * | s059146046 | Accepted | p02869 | Input is given from Standard Input in the following format:
N K | N, K = map(int, input().split())
l = [0] * 3 * N
for i in range(3 * N):
z = (i // (2 * N)) * (
3
* (
(i % 2) * (N // 2 - (i % N) // 2 - 1)
+ (1 - i % 2) * (-(i % N) // 2 - N % 2)
)
)
# print(i+K,z)
# print(i+K,(i//N+3*(i%N)+(i//N)*3*((N+1)//2)))
l[(i // N + 3 * (i % N) + (i // N) * 3 * ((N + 1) // 2) + z) % (3 * N)] = i + K
s = ("{} " * 3 + "\n") * N
print(-1 if 2 * K - 1 > N else s.format(*l))
# print(%(*l))
| Statement
Given are positive integers N and K.
Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N
triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is
satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one
of those triples.
* For every integer i from 1 to N, a_i + b_i \leq c_i holds.
If the answer is yes, construct one such partition. | [{"input": "1 1", "output": "1 2 3\n \n\n* * *"}, {"input": "3 3", "output": "-1"}] |
If it is impossible to partition the integers satisfying the condition, print
`-1`. If it is possible, print N triples in the following format:
a_1 b_1 c_1
:
a_N b_N c_N
* * * | s326825346 | Accepted | p02869 | Input is given from Standard Input in the following format:
N K | # -*- coding: utf-8 -*-
def solve():
N, K = map(int, input().split())
if K > (N + 1) / 2:
return "-1"
L = [[K, K + N, K + 2 * N] for i in range(N)]
for i in range(N):
if N % 2:
j = (N - 1 - 2 * i) % N
k = (2 * i) % N
else:
j = (N - 1 - 2 * i) % N - i // (N // 2)
k = (1 + 2 * i) % N - i // (N // 2)
L[i][0] += i
L[j][1] += i
L[k][2] += i
res = "\n".join(" ".join(map(str, l)) for l in L)
return res
if __name__ == "__main__":
print(solve())
| Statement
Given are positive integers N and K.
Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N
triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is
satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one
of those triples.
* For every integer i from 1 to N, a_i + b_i \leq c_i holds.
If the answer is yes, construct one such partition. | [{"input": "1 1", "output": "1 2 3\n \n\n* * *"}, {"input": "3 3", "output": "-1"}] |
Print the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
* * * | s816666182 | Accepted | p02644 | Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W} | def main():
h, a, *m = open(0)
h, w, k, a, b, f, g = map(int, (h + a).split())
I = h * w
d = [I] * I
a = ~w + a * w + b
d[a] = 1
q = [a]
for s in q:
for y, x in (1, 0), (-1, 0), (0, 1), (0, -1):
for z in range(k):
i, j = s // w + y * ~z, s % w + x * ~z
t = i * w + j
if not h > i > -1 < j < w or "." < m[i][j] or d[t] <= d[s]:
break
if d[t] == I:
q += (t,)
d[t] = d[s] + 1
print(d[~w + f * w + g] % I - 1)
main()
| Statement
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid
with H east-west rows and W north-south columns. Let (i,j) be the square at
the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square
(i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is
`.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one
of the four directions: north, east, south, and west. The move may not pass
through a square with a lotus leaf. Moving to such a square or out of the pond
is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is
impossible, point out that fact. | [{"input": "3 5 2\n 3 2 3 4\n .....\n .@..@\n ..@..", "output": "5\n \n\nInitially, Snuke is at the square (3,2). He can reach the square (3, 4) by\nmaking five strokes as follows:\n\n * From (3, 2), go west one square to (3, 1).\n\n * From (3, 1), go north two squares to (1, 1).\n\n * From (1, 1), go east two squares to (1, 3).\n\n * From (1, 3), go east one square to (1, 4).\n\n * From (1, 4), go south two squares to (3, 4).\n\n* * *"}, {"input": "1 6 4\n 1 1 1 6\n ......", "output": "2\n \n\n* * *"}, {"input": "3 3 1\n 2 1 2 3\n .@.\n .@.\n .@.", "output": "-1"}] |
Print the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
* * * | s401194929 | Runtime Error | p02644 | Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W} | import sys
def main(lines):
n, m, s = map(int, lines[0].split())
adj = [[] for _ in range(n)]
for i in range(m):
a, b, d = map(int, lines[i + 1].split())
adj[a].append((b, d))
from heapq import heappush, heappop
inf = 10**9
node = []
dist = [inf] * n
done = [False] * n
dist[s] = 0
heappush(node, (0, s))
while node:
cost, v = heappop(node)
if not done[v]:
for e in adj[v]:
if dist[e[0]] > dist[v] + e[1]:
dist[e[0]] = dist[v] + e[1]
heappush(node, (dist[e[0]], e[0]))
done[v] = True
for el in dist:
if el == inf:
print("INF")
else:
print(el)
if __name__ == "__main__":
lines = []
for l in sys.stdin:
lines.append(l.rstrip("\r\n"))
main(lines)
| Statement
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid
with H east-west rows and W north-south columns. Let (i,j) be the square at
the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square
(i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is
`.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one
of the four directions: north, east, south, and west. The move may not pass
through a square with a lotus leaf. Moving to such a square or out of the pond
is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is
impossible, point out that fact. | [{"input": "3 5 2\n 3 2 3 4\n .....\n .@..@\n ..@..", "output": "5\n \n\nInitially, Snuke is at the square (3,2). He can reach the square (3, 4) by\nmaking five strokes as follows:\n\n * From (3, 2), go west one square to (3, 1).\n\n * From (3, 1), go north two squares to (1, 1).\n\n * From (1, 1), go east two squares to (1, 3).\n\n * From (1, 3), go east one square to (1, 4).\n\n * From (1, 4), go south two squares to (3, 4).\n\n* * *"}, {"input": "1 6 4\n 1 1 1 6\n ......", "output": "2\n \n\n* * *"}, {"input": "3 3 1\n 2 1 2 3\n .@.\n .@.\n .@.", "output": "-1"}] |
Print the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
* * * | s300619540 | Runtime Error | p02644 | Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W} | # -*- coding: utf-8 -*-
H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
C = []
for _ in range(H):
C.append(input())
count_matrix = [[float("inf") for _ in range(W)] for _ in range(H)]
def calc(count, pos, to_dir, move_count):
if count_matrix[pos["x"]][pos["y"]] <= count:
return
count_matrix[pos["x"]][pos["y"]] = count
if to_dir == "N" or to_dir == "S":
if to_dir == "N" and can_move(to_n(pos)):
if move_count == K:
count += 1
move_count = 0
calc(count, to_n(pos), "N", move_count + 1)
if to_dir == "S" and can_move(to_s(pos)):
if move_count == K:
count += 1
move_count = 0
calc(count, to_s(pos), "S", move_count + 1)
if can_move(to_w(pos)):
calc(count + 1, to_w(pos), "W", 1)
if can_move(to_e(pos)):
calc(count + 1, to_e(pos), "E", 1)
if to_dir == "W" or to_dir == "E":
if to_dir == "W" and can_move(to_w(pos)):
if move_count == K:
count += 1
move_count = 0
calc(count, to_w(pos), "W", move_count + 1)
if to_dir == "E" and can_move(to_e(pos)):
if move_count == K:
count += 1
move_count = 0
calc(count, to_e(pos), "E", move_count + 1)
if can_move(to_n(pos)):
calc(count + 1, to_n(pos), "N", 1)
if can_move(to_s(pos)):
calc(count + 1, to_s(pos), "S", 1)
return
def can_move(pos):
return (
0 <= pos["x"] <= H - 1
and 0 <= pos["y"] <= W - 1
and C[pos["x"]][pos["y"]] != "@"
)
def to_n(pos):
return {"x": pos["x"] - 1, "y": pos["y"]}
def to_s(pos):
return {"x": pos["x"] + 1, "y": pos["y"]}
def to_w(pos):
return {"x": pos["x"], "y": pos["y"] - 1}
def to_e(pos):
return {"x": pos["x"], "y": pos["y"] + 1}
px = x2 - 1
py = y2 - 1
dest_pos = {"x": px, "y": py}
if can_move(to_n(dest_pos)):
calc(1, to_n(dest_pos), "N", 1)
if can_move(to_s(dest_pos)):
calc(1, to_s(dest_pos), "S", 1)
if can_move(to_w(dest_pos)):
calc(1, to_w(dest_pos), "W", 1)
if can_move(to_e(dest_pos)):
calc(1, to_e(dest_pos), "E", 1)
ans = count_matrix[x1 - 1][y1 - 1]
print(ans if ans != float("inf") else -1)
| Statement
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid
with H east-west rows and W north-south columns. Let (i,j) be the square at
the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square
(i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is
`.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one
of the four directions: north, east, south, and west. The move may not pass
through a square with a lotus leaf. Moving to such a square or out of the pond
is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is
impossible, point out that fact. | [{"input": "3 5 2\n 3 2 3 4\n .....\n .@..@\n ..@..", "output": "5\n \n\nInitially, Snuke is at the square (3,2). He can reach the square (3, 4) by\nmaking five strokes as follows:\n\n * From (3, 2), go west one square to (3, 1).\n\n * From (3, 1), go north two squares to (1, 1).\n\n * From (1, 1), go east two squares to (1, 3).\n\n * From (1, 3), go east one square to (1, 4).\n\n * From (1, 4), go south two squares to (3, 4).\n\n* * *"}, {"input": "1 6 4\n 1 1 1 6\n ......", "output": "2\n \n\n* * *"}, {"input": "3 3 1\n 2 1 2 3\n .@.\n .@.\n .@.", "output": "-1"}] |
Print the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
* * * | s412732430 | Accepted | p02644 | Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W} | import sys
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
state = [list(input().rstrip()) for _ in range(H)]
q = [(x1 - 1, y1 - 1)]
checked = [[-1] * W for _ in range(H)]
checked[x1 - 1][y1 - 1] = 0
while q:
qq = []
for x, y in q:
d = checked[x][y]
dx = 1
while x + dx < H and state[x + dx][y] == ord(".") and dx <= K:
if checked[x + dx][y] == -1:
checked[x + dx][y] = d + 1
qq.append((x + dx, y))
elif checked[x + dx][y] >= d + 1:
checked[x + dx][y] = d + 1
else:
break
dx += 1
dx = -1
while x + dx >= 0 and state[x + dx][y] == ord(".") and dx >= -K:
if checked[x + dx][y] == -1:
checked[x + dx][y] = d + 1
qq.append((x + dx, y))
elif checked[x + dx][y] >= d + 1:
checked[x + dx][y] = d + 1
else:
break
dx -= 1
dy = 1
while y + dy < W and state[x][y + dy] == ord(".") and dy <= K:
if checked[x][y + dy] == -1:
checked[x][y + dy] = d + 1
qq.append((x, y + dy))
elif checked[x][y + dy] >= d + 1:
checked[x][y + dy] = d + 1
else:
break
dy += 1
dy = -1
while y + dy >= 0 and state[x][y + dy] == ord(".") and dy >= -K:
if checked[x][y + dy] == -1:
checked[x][y + dy] = d + 1
qq.append((x, y + dy))
elif checked[x][y + dy] >= d + 1:
checked[x][y + dy] = d + 1
else:
break
dy -= 1
q = qq
print(checked[x2 - 1][y2 - 1])
| Statement
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid
with H east-west rows and W north-south columns. Let (i,j) be the square at
the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square
(i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is
`.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one
of the four directions: north, east, south, and west. The move may not pass
through a square with a lotus leaf. Moving to such a square or out of the pond
is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is
impossible, point out that fact. | [{"input": "3 5 2\n 3 2 3 4\n .....\n .@..@\n ..@..", "output": "5\n \n\nInitially, Snuke is at the square (3,2). He can reach the square (3, 4) by\nmaking five strokes as follows:\n\n * From (3, 2), go west one square to (3, 1).\n\n * From (3, 1), go north two squares to (1, 1).\n\n * From (1, 1), go east two squares to (1, 3).\n\n * From (1, 3), go east one square to (1, 4).\n\n * From (1, 4), go south two squares to (3, 4).\n\n* * *"}, {"input": "1 6 4\n 1 1 1 6\n ......", "output": "2\n \n\n* * *"}, {"input": "3 3 1\n 2 1 2 3\n .@.\n .@.\n .@.", "output": "-1"}] |
Print the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
* * * | s496483320 | Wrong Answer | p02644 | Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W} | import collections
H, W, K = [int(_) for _ in input().split()]
x1, y1, x2, y2 = [int(_) - 1 for _ in input().split()]
C = [[10**6 if s == "." else None for s in input()] for _ in range(H)]
C[x1][y1] = 0
Qx = collections.deque([(x1, y1)]) # 次にxが変化
Qy = collections.deque([(x1, y1)]) # 次にyが変化
while True:
if not (Qx or Qy):
break
Qy2 = collections.deque([])
while Qx:
x, y = Qx.popleft()
for nx in range(x + 1, H):
if C[nx][y] is None:
break
elif C[nx][y] == 10**6:
Qy2 += [(nx, y)]
C[nx][y] = C[x][y] + 1 + (nx - x - 1) // K
for nx in range(x - 1, -1, -1):
if C[nx][y] is None:
break
elif C[nx][y] == 10**6:
Qy2 += [(nx, y)]
C[nx][y] = C[x][y] + 1 + (x - nx - 1) // K
Qx2 = collections.deque([])
while Qy:
x, y = Qy.popleft()
for ny in range(y + 1, W):
if C[x][ny] is None:
break
elif C[x][ny] == 10**6:
Qx2 += [(x, ny)]
C[x][ny] = C[x][y] + 1 + (ny - y - 1) // K
for ny in range(y - 1, -1, -1):
if C[x][ny] is None:
break
elif C[x][ny] == 10**6:
Qx2 += [(x, ny)]
C[x][ny] = C[x][y] + 1 + (y - ny - 1) // K
Qx = Qx2
Qy = Qy2
ans = C[x2][y2]
print(ans if ans < 10**6 else -1)
| Statement
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid
with H east-west rows and W north-south columns. Let (i,j) be the square at
the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square
(i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is
`.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one
of the four directions: north, east, south, and west. The move may not pass
through a square with a lotus leaf. Moving to such a square or out of the pond
is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is
impossible, point out that fact. | [{"input": "3 5 2\n 3 2 3 4\n .....\n .@..@\n ..@..", "output": "5\n \n\nInitially, Snuke is at the square (3,2). He can reach the square (3, 4) by\nmaking five strokes as follows:\n\n * From (3, 2), go west one square to (3, 1).\n\n * From (3, 1), go north two squares to (1, 1).\n\n * From (1, 1), go east two squares to (1, 3).\n\n * From (1, 3), go east one square to (1, 4).\n\n * From (1, 4), go south two squares to (3, 4).\n\n* * *"}, {"input": "1 6 4\n 1 1 1 6\n ......", "output": "2\n \n\n* * *"}, {"input": "3 3 1\n 2 1 2 3\n .@.\n .@.\n .@.", "output": "-1"}] |
Print the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
* * * | s078966519 | Accepted | p02644 | Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W} | import sys
import numpy as np
from numba import njit
from heapq import heappop, heappush
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit("(b1[:],i8,i8,i8,i8,i8)", cache=True)
def main(C, H, W, S, T, K):
INF = 10**18
N = H * W
q = [5 * S]
dist = np.full((5 * N), INF, np.int64)
dist[5 * S] = 0
move = [0, 1, -1, W, -W]
B = 5 * N + 10
while q:
x = heappop(q)
dist_x, x = divmod(x, B)
if dist_x > dist[x]:
continue
v, d = divmod(x, 5)
if d == 0:
# どちらかに進む
for i in range(1, 5):
w = v + move[i]
y = 5 * w + i
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
else:
# 直進する
if dist_x % K != 0:
w = v + move[d]
y = 5 * w + d
dist_y = dist_x + 1
if C[w] and dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
# 止まって向きを変える権利を得る
y = 5 * v
dist_y = dist_x + (-dist_x) % K
if dist_y < dist[y]:
dist[y] = dist_y
heappush(q, B * dist_y + y)
x = dist[5 * T]
if x == INF:
return -1
return dist[5 * T] // K
H, W, K = map(int, readline().split())
x1, y1, x2, y2 = map(int, readline().split())
C = np.zeros((H + 2, W + 2), np.bool_)
C[1:-1, 1:-1] = np.frombuffer(read(), "S1").reshape(H, -1)[:, :W] == b"."
C = C.ravel()
H += 2
W += 2
S = W * x1 + y1
T = W * x2 + y2
print(main(C, H, W, S, T, K))
| Statement
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid
with H east-west rows and W north-south columns. Let (i,j) be the square at
the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square
(i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is
`.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one
of the four directions: north, east, south, and west. The move may not pass
through a square with a lotus leaf. Moving to such a square or out of the pond
is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is
impossible, point out that fact. | [{"input": "3 5 2\n 3 2 3 4\n .....\n .@..@\n ..@..", "output": "5\n \n\nInitially, Snuke is at the square (3,2). He can reach the square (3, 4) by\nmaking five strokes as follows:\n\n * From (3, 2), go west one square to (3, 1).\n\n * From (3, 1), go north two squares to (1, 1).\n\n * From (1, 1), go east two squares to (1, 3).\n\n * From (1, 3), go east one square to (1, 4).\n\n * From (1, 4), go south two squares to (3, 4).\n\n* * *"}, {"input": "1 6 4\n 1 1 1 6\n ......", "output": "2\n \n\n* * *"}, {"input": "3 3 1\n 2 1 2 3\n .@.\n .@.\n .@.", "output": "-1"}] |
Print the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
* * * | s501842365 | Accepted | p02644 | Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W} | #!/usr/bin/env python3
# fast input
from heapq import heappop, heappush
import sys
input = sys.stdin.buffer.readline
INF = 10**10
# INF = float("inf")
def main(H, W, K, x1, y1, x2, y2, mapdata):
start = x1 * W + y1
goal = x2 * W + y2
NUM_DIR = 4
distances = [(INF, 0)] * (H * W * NUM_DIR)
key = start * NUM_DIR
distances[key] = (0, 0)
distances[key + 2] = (0, 0)
shortest_path = [0] * (H * W * NUM_DIR)
shortest_path[key] = 0
queue = [((0, 0), key), ((0, 0), key + 2)]
DIRS = [(1, 0), (-1, 0), (0, 1), (0, -1)]
while queue:
(d, frac), pos_dir = heappop(queue)
pos, direction = divmod(pos_dir, NUM_DIR)
x, y = divmod(pos, W)
dist = distances[pos_dir]
if dist < (d, frac):
continue
if pos == goal:
break
dx, dy = DIRS[direction]
nx = x + dx
ny = y + dy
# dp("nx, ny", nx, ny)
if mapdata[nx * W + ny]:
if frac == 0:
newd = d + 1
newfrac = -K + 1
else:
newd = d
newfrac = frac + 1
newdist = (newd, newfrac)
to = (nx * W + ny) * NUM_DIR + direction
if distances[to] > newdist:
# found shorter path
distances[to] = newdist
heappush(queue, (newdist, to))
shortest_path[to] = pos_dir
if direction < 2:
# facing X axis
dir = 2
nx = x
ny = y + 1
if mapdata[nx * W + ny]:
newdist = (d + 1, -K + 1)
to = (nx * W + ny) * NUM_DIR + dir
if distances[to] > newdist:
# found shorter path
distances[to] = newdist
heappush(queue, (newdist, to))
shortest_path[to] = pos_dir
dir = 3
nx = x
ny = y - 1
if mapdata[nx * W + ny]:
newdist = (d + 1, -K + 1)
to = (nx * W + ny) * NUM_DIR + dir
if distances[to] > newdist:
# found shorter path
distances[to] = newdist
heappush(queue, (newdist, to))
shortest_path[to] = pos_dir
if direction > 1:
# facing Y axis
dir = 0
nx = x + 1
ny = y
if mapdata[nx * W + ny]:
newdist = (d + 1, -K + 1)
to = (nx * W + ny) * NUM_DIR + dir
if distances[to] > newdist:
# found shorter path
distances[to] = newdist
heappush(queue, (newdist, to))
shortest_path[to] = pos_dir
dir = 1
nx = x - 1
ny = y
if mapdata[nx * W + ny]:
newdist = (d + 1, -K + 1)
to = (nx * W + ny) * NUM_DIR + dir
if distances[to] > newdist:
# found shorter path
distances[to] = newdist
heappush(queue, (newdist, to))
shortest_path[to] = pos_dir
result = min(distances[goal * NUM_DIR : goal * NUM_DIR + NUM_DIR])
if result[0] == INF:
# unreachable
return -1
else:
return result[0]
# print(sys.argv)
if sys.argv[-1] == "ONLINE_JUDGE":
print("compiling")
from numba.pycc import CC
cc = CC("my_module")
cc.export("main", "i8(i8,i8,i8,i8,i8,i8,i8,b1[:])")(main)
cc.compile()
exit()
else:
H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
from my_module import main
import numpy as np
C = np.zeros((H + 2, W + 2), np.bool_)
data = np.frombuffer(sys.stdin.buffer.read(), "S1")
# print(data)
data = data.reshape(H, -1)
# print(data)
data = data[:, :W] == b"."
# print(data)
C[1:-1, 1:-1] = data
C = C.ravel()
H += 2
W += 2
print(main(H, W, K, x1, y1, x2, y2, C))
| Statement
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid
with H east-west rows and W north-south columns. Let (i,j) be the square at
the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square
(i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is
`.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one
of the four directions: north, east, south, and west. The move may not pass
through a square with a lotus leaf. Moving to such a square or out of the pond
is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is
impossible, point out that fact. | [{"input": "3 5 2\n 3 2 3 4\n .....\n .@..@\n ..@..", "output": "5\n \n\nInitially, Snuke is at the square (3,2). He can reach the square (3, 4) by\nmaking five strokes as follows:\n\n * From (3, 2), go west one square to (3, 1).\n\n * From (3, 1), go north two squares to (1, 1).\n\n * From (1, 1), go east two squares to (1, 3).\n\n * From (1, 3), go east one square to (1, 4).\n\n * From (1, 4), go south two squares to (3, 4).\n\n* * *"}, {"input": "1 6 4\n 1 1 1 6\n ......", "output": "2\n \n\n* * *"}, {"input": "3 3 1\n 2 1 2 3\n .@.\n .@.\n .@.", "output": "-1"}] |
Print the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
* * * | s214253955 | Accepted | p02644 | Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W} | def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(map(int, input().split()))
def main():
from collections import deque
H, W, K = MI()
x1, y1, x2, y2 = MI()
C = []
C.append(["@"] * (W + 2))
for _ in range(H):
c = ["@"] + list(input()) + ["@"]
C.append(c)
C.append(["@"] * (W + 2))
# 各ますにつき4方向分のデータを持つ,コストは(移動回数,今直線で動いた数)でもつ,移動回数がより重要視される
inf = 10**10
D = [
[[(inf, inf)] * 4 for _ in range(W + 2)] for _ in range(H + 2)
] # 下上右左の4方向
# D[i][j][k]はi行j列k向き
dq = deque()
for k in range(4):
D[x1][y1][k] = (0, 0)
dq.append((x1, y1, k, 0, 0))
dx = [1, -1, 0, 0]
dy = [0, 0, -1, 1]
# 01BFSでいけそう
while len(dq):
x, y, d, cnt, k = dq.popleft()
for nd in range(4):
# 方向そのまま
if nd == d:
nx = x + dx[nd]
ny = y + dy[nd]
nk = (k + 1) % K
ncnt = cnt
if k + 1 >= K:
ncnt += 1
# 方向転換
else:
nk = 0
ncnt = cnt
if k != 0:
ncnt += 1
nx = x
ny = y
if C[nx][ny] == ".":
if D[nx][ny][nd] > (ncnt, nk): # 更新する場合だけ
D[nx][ny][nd] = (ncnt, nk)
if ncnt == cnt:
dq.appendleft((nx, ny, nd, ncnt, nk))
else:
dq.append((nx, ny, nd, ncnt, nk))
ans = inf
for d in range(4):
temp = D[x2][y2][d][0]
if D[x2][y2][d][1]:
temp += 1
ans = min(ans, temp)
if ans >= inf:
ans = -1
print(ans)
# for i in range(1,H+1):
# for j in range(1,W+1):
# print(D[i][j])
main()
| Statement
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid
with H east-west rows and W north-south columns. Let (i,j) be the square at
the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square
(i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is
`.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one
of the four directions: north, east, south, and west. The move may not pass
through a square with a lotus leaf. Moving to such a square or out of the pond
is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square
(x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is
impossible, point out that fact. | [{"input": "3 5 2\n 3 2 3 4\n .....\n .@..@\n ..@..", "output": "5\n \n\nInitially, Snuke is at the square (3,2). He can reach the square (3, 4) by\nmaking five strokes as follows:\n\n * From (3, 2), go west one square to (3, 1).\n\n * From (3, 1), go north two squares to (1, 1).\n\n * From (1, 1), go east two squares to (1, 3).\n\n * From (1, 3), go east one square to (1, 4).\n\n * From (1, 4), go south two squares to (3, 4).\n\n* * *"}, {"input": "1 6 4\n 1 1 1 6\n ......", "output": "2\n \n\n* * *"}, {"input": "3 3 1\n 2 1 2 3\n .@.\n .@.\n .@.", "output": "-1"}] |
Print the answer.
* * * | s772619554 | Wrong Answer | p03405 | Input is given from Standard Input in the following format:
N M
X
U_1 V_1 W_1
U_2 V_2 W_2
:
U_M V_M W_M | # E
import numpy as np
N, M = map(int, input().split())
X = int(input())
U_list = []
V_list = []
W_list = []
for _ in range(M):
u, v, w = map(int, input().split())
U_list.append(u)
V_list.append(v)
W_list.append(w)
ind_vec = np.arange(N + 1)
def find_parent(k):
l = ind_vec[k]
search_list = []
while l != k:
search_list.append(k)
k = l
l = ind_vec[k]
return k, search_list
w_arr = np.array(W_list)
w_arg = np.argsort(w_arr)
min_weight = 0
max_weight = 0
for m in range(M):
i = w_arg[m]
u = U_list[i]
v = V_list[i]
up, ul = find_parent(u)
for j in ul:
ind_vec[j] = up
vp, vl = find_parent(v)
for j in vl:
ind_vec[j] = vp
if up != vp:
min_weight += W_list[i]
ind_vec[vp] = up
max_weight = W_list[i]
# min = W
cnt_small = 0
for i in range(M):
if W_list[i] <= max_weight:
cnt_small += 1
if min_weight == X:
print(
(pow(2, cnt_small, 10**9 + 7) - 2)
* pow(2, M - cnt_small, 10**9 + 7)
% (10**9 + 7)
)
elif min_weight > X:
print(0)
else:
print(pow(2, M - cnt_small, 10**9 + 7))
| Statement
We have an undirected weighted graph with N vertices and M edges. The i-th
edge in the graph connects Vertex U_i and Vertex V_i, and has a weight of W_i.
Additionally, you are given an integer X.
Find the number of ways to paint each edge in this graph either white or black
such that the following condition is met, modulo 10^9 + 7:
* The graph has a spanning tree that contains both an edge painted white and an edge painted black. Furthermore, among such spanning trees, the one with the smallest weight has a weight of X.
Here, the weight of a spanning tree is the sum of the weights of the edges
contained in the spanning tree. | [{"input": "3 3\n 2\n 1 2 1\n 2 3 1\n 3 1 1", "output": "6\n \n\n* * *"}, {"input": "3 3\n 3\n 1 2 1\n 2 3 1\n 3 1 2", "output": "2\n \n\n* * *"}, {"input": "5 4\n 1\n 1 2 3\n 1 3 3\n 2 4 6\n 2 5 8", "output": "0\n \n\n* * *"}, {"input": "8 10\n 49\n 4 6 10\n 8 4 11\n 5 8 9\n 1 8 10\n 3 8 128773450\n 7 8 10\n 4 2 4\n 3 4 1\n 3 1 13\n 5 2 2", "output": "4"}] |
Print `First` if Takahashi will win, and print `Second` if Aoki will win.
* * * | s646444085 | Runtime Error | p03055 | Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_{N-1} b_{N-1} | def s(x, v, d):
r = [d, v]
for u in g[v]:
if u != x:
t = s(v, u, d + 1)
if r[0] < t[0]:
r = t
return r
n, *t = map(int, open(0).read().split())
g = [set() for _ in range(n + 1)]
for a, b in zip(t[::2], t[1::2]):
g[a].add(b)
g[b].add(a)
print("SFeicrosntd"[s(0, s(0, 1, 0)[1], 0)[0] % 3 != 1 :: 2])
| Statement
Takahashi and Aoki will play a game on a tree. The tree has N vertices
numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex
b_i.
At the beginning of the game, each vertex contains a coin. Starting from
Takahashi, he and Aoki will alternately perform the following operation:
* Choose a vertex v that contains one or more coins, and remove all the coins from v.
* Then, move each coin remaining on the tree to the vertex that is nearest to v among the adjacent vertices of the coin's current vertex.
The player who becomes unable to play, loses the game. That is, the player who
takes his turn when there is no coin remaining on the tree, loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "3\n 1 2\n 2 3", "output": "First\n \n\nHere is one possible progress of the game:\n\n * Takahashi removes the coin from Vertex 1. Now, Vertex 1 and Vertex 2 contain one coin each.\n * Aoki removes the coin from Vertex 2. Now, Vertex 2 contains one coin.\n * Takahashi removes the coin from Vertex 2. Now, there is no coin remaining on the tree.\n * Aoki takes his turn when there is no coin on the tree and loses.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 2 4\n 4 6\n 5 6", "output": "Second\n \n\n* * *"}, {"input": "7\n 1 7\n 7 4\n 3 4\n 7 5\n 6 3\n 2 1", "output": "First"}] |
Print `First` if Takahashi will win, and print `Second` if Aoki will win.
* * * | s351273607 | Accepted | p03055 | Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_{N-1} b_{N-1} | class Tree:
def __init__(self, n, decrement=1):
self.n = n
self.edges = [[] for _ in range(n)]
self.root = None
self.depth = [-1] * n
self.size = [1] * n # 部分木のノードの数
self.decrement = decrement
def add_edge(self, u, v):
u, v = u - self.decrement, v - self.decrement
self.edges[u].append(v)
self.edges[v].append(u)
def add_edges(self, edges):
for u, v in edges:
u, v = u - self.decrement, v - self.decrement
self.edges[u].append(v)
self.edges[v].append(u)
def set_root(self, root):
root -= self.decrement
self.root = root
self.par = [-1] * self.n
self.depth[root] = 0
self.order = [root] # 帰りがけに使う
next_set = [root]
while next_set:
p = next_set.pop()
for q in self.edges[p]:
if self.depth[q] != -1:
continue
self.par[q] = p
self.depth[q] = self.depth[p] + 1
self.order.append(q)
next_set.append(q)
for p in self.order[::-1]:
for q in self.edges[p]:
if self.par[p] == q:
continue
self.size[p] += self.size[q]
def diameter(self, path=False):
# assert self.root is not None
u = self.depth.index(max(self.depth))
dist = [-1] * self.n
dist[u] = 0
prev = [-1] * self.n
next_set = [u]
while next_set:
p = next_set.pop()
for q in self.edges[p]:
if dist[q] != -1:
continue
dist[q] = dist[p] + 1
prev[q] = p
next_set.append(q)
d = max(dist)
if path:
v = w = dist.index(d)
path = [v + 1]
while w != u:
w = prev[w]
path.append(w + self.decrement)
return d, v + self.decrement, u + self.decrement, path
else:
return d
def heavy_light_decomposition(self):
"""
heavy edge を並べてリストにした物を返す (1-indexed if decrement=True)
"""
# assert self.root is not None
self.vid = [-1] * self.n
self.hld = [-1] * self.n
self.head = [-1] * self.n
self.head[self.root] = self.root
self.heavy_node = [-1] * self.n
next_set = [self.root]
for i in range(self.n):
"""for tree graph, dfs ends in N times"""
p = next_set.pop()
self.vid[p] = i
self.hld[i] = p + self.decrement
maxs = 0
for q in self.edges[p]:
"""encode direction of Heavy edge into heavy_node"""
if self.par[p] == q:
continue
if maxs < self.size[q]:
maxs = self.size[q]
self.heavy_node[p] = q
for q in self.edges[p]:
"""determine "head" of heavy edge"""
if self.par[p] == q or self.heavy_node[p] == q:
continue
self.head[q] = q
next_set.append(q)
if self.heavy_node[p] != -1:
self.head[self.heavy_node[p]] = self.head[p]
next_set.append(self.heavy_node[p])
return self.hld
def lca(self, u, v):
# assert self.head is not None
u, v = u - self.decrement, v - self.decrement
while True:
if self.vid[u] > self.vid[v]:
u, v = v, u
if self.head[u] != self.head[v]:
v = self.par[self.head[v]]
else:
return u + self.decrement
def path(self, u, v):
"""u-v 間の最短経路をリストで返す"""
p = self.lca(u, v)
u, v, p = u - self.decrement, v - self.decrement, p - self.decrement
R = []
while u != p:
yield u + self.decrement
u = self.par[u]
yield p + self.decrement
while v != p:
R.append(v)
v = self.par[v]
for v in reversed(R):
yield v + self.decrement
def distance(self, u, v):
# assert self.head is not None
p = self.lca(u, v)
u, v, p = u - self.decrement, v - self.decrement, p - self.decrement
return self.depth[u] + self.depth[v] - 2 * self.depth[p]
def find(self, u, v, x):
return self.distance(u, x) + self.distance(x, v) == self.distance(u, v)
def path_to_list(self, u, v, edge_query=False):
"""
パス上の頂点の集合を self.hld 上の開区間の集合として表す
ここで、self.hld は heavy edge を並べて数列にしたものである
"""
# assert self.head is not None
u, v = u - self.decrement, v - self.decrement
while True:
if self.vid[u] > self.vid[v]:
u, v = v, u
if self.head[u] != self.head[v]:
yield self.vid[self.head[v]], self.vid[v] + 1
v = self.par[self.head[v]]
else:
yield self.vid[u] + edge_query, self.vid[v] + 1
return
def point(self, u):
return self.vid[u - self.decrement]
def subtree_query(self, u):
u -= self.decrement
return self.vid[u], self.vid[u] + self.size[u]
def draw(self):
import matplotlib.pyplot as plt
import networkx as nx
G = nx.Graph()
for x in range(self.n):
for y in self.edges[x]:
G.add_edge(x + self.decrement, y + self.decrement)
pos = nx.spring_layout(G)
nx.draw_networkx(G, pos)
plt.axis("off")
plt.show()
##################################################################################################
import sys
input = sys.stdin.readline
N = int(input())
T = Tree(N)
for _ in range(N - 1):
x, y = map(int, input().split())
T.add_edge(x, y)
T.set_root(1)
print("Second" if (T.diameter() + 1) % 3 == 2 else "First")
| Statement
Takahashi and Aoki will play a game on a tree. The tree has N vertices
numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex
b_i.
At the beginning of the game, each vertex contains a coin. Starting from
Takahashi, he and Aoki will alternately perform the following operation:
* Choose a vertex v that contains one or more coins, and remove all the coins from v.
* Then, move each coin remaining on the tree to the vertex that is nearest to v among the adjacent vertices of the coin's current vertex.
The player who becomes unable to play, loses the game. That is, the player who
takes his turn when there is no coin remaining on the tree, loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "3\n 1 2\n 2 3", "output": "First\n \n\nHere is one possible progress of the game:\n\n * Takahashi removes the coin from Vertex 1. Now, Vertex 1 and Vertex 2 contain one coin each.\n * Aoki removes the coin from Vertex 2. Now, Vertex 2 contains one coin.\n * Takahashi removes the coin from Vertex 2. Now, there is no coin remaining on the tree.\n * Aoki takes his turn when there is no coin on the tree and loses.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 2 4\n 4 6\n 5 6", "output": "Second\n \n\n* * *"}, {"input": "7\n 1 7\n 7 4\n 3 4\n 7 5\n 6 3\n 2 1", "output": "First"}] |
Print `First` if Takahashi will win, and print `Second` if Aoki will win.
* * * | s362124380 | Wrong Answer | p03055 | Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_{N-1} b_{N-1} | n, *a = open(0).read().split()
print(["Second", "First"][a.count(n) % 2])
| Statement
Takahashi and Aoki will play a game on a tree. The tree has N vertices
numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex
b_i.
At the beginning of the game, each vertex contains a coin. Starting from
Takahashi, he and Aoki will alternately perform the following operation:
* Choose a vertex v that contains one or more coins, and remove all the coins from v.
* Then, move each coin remaining on the tree to the vertex that is nearest to v among the adjacent vertices of the coin's current vertex.
The player who becomes unable to play, loses the game. That is, the player who
takes his turn when there is no coin remaining on the tree, loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "3\n 1 2\n 2 3", "output": "First\n \n\nHere is one possible progress of the game:\n\n * Takahashi removes the coin from Vertex 1. Now, Vertex 1 and Vertex 2 contain one coin each.\n * Aoki removes the coin from Vertex 2. Now, Vertex 2 contains one coin.\n * Takahashi removes the coin from Vertex 2. Now, there is no coin remaining on the tree.\n * Aoki takes his turn when there is no coin on the tree and loses.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 2 4\n 4 6\n 5 6", "output": "Second\n \n\n* * *"}, {"input": "7\n 1 7\n 7 4\n 3 4\n 7 5\n 6 3\n 2 1", "output": "First"}] |
Print `First` if Takahashi will win, and print `Second` if Aoki will win.
* * * | s237814587 | Wrong Answer | p03055 | Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_{N-1} b_{N-1} | print("SFeicrosntd"[int(input()) % 2 :: 2])
| Statement
Takahashi and Aoki will play a game on a tree. The tree has N vertices
numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex
b_i.
At the beginning of the game, each vertex contains a coin. Starting from
Takahashi, he and Aoki will alternately perform the following operation:
* Choose a vertex v that contains one or more coins, and remove all the coins from v.
* Then, move each coin remaining on the tree to the vertex that is nearest to v among the adjacent vertices of the coin's current vertex.
The player who becomes unable to play, loses the game. That is, the player who
takes his turn when there is no coin remaining on the tree, loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "3\n 1 2\n 2 3", "output": "First\n \n\nHere is one possible progress of the game:\n\n * Takahashi removes the coin from Vertex 1. Now, Vertex 1 and Vertex 2 contain one coin each.\n * Aoki removes the coin from Vertex 2. Now, Vertex 2 contains one coin.\n * Takahashi removes the coin from Vertex 2. Now, there is no coin remaining on the tree.\n * Aoki takes his turn when there is no coin on the tree and loses.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 2 4\n 4 6\n 5 6", "output": "Second\n \n\n* * *"}, {"input": "7\n 1 7\n 7 4\n 3 4\n 7 5\n 6 3\n 2 1", "output": "First"}] |
Print `First` if Takahashi will win, and print `Second` if Aoki will win.
* * * | s006316836 | Wrong Answer | p03055 | Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_{N-1} b_{N-1} | print(["Second", "First"][int(input()) % 2])
| Statement
Takahashi and Aoki will play a game on a tree. The tree has N vertices
numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex
b_i.
At the beginning of the game, each vertex contains a coin. Starting from
Takahashi, he and Aoki will alternately perform the following operation:
* Choose a vertex v that contains one or more coins, and remove all the coins from v.
* Then, move each coin remaining on the tree to the vertex that is nearest to v among the adjacent vertices of the coin's current vertex.
The player who becomes unable to play, loses the game. That is, the player who
takes his turn when there is no coin remaining on the tree, loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "3\n 1 2\n 2 3", "output": "First\n \n\nHere is one possible progress of the game:\n\n * Takahashi removes the coin from Vertex 1. Now, Vertex 1 and Vertex 2 contain one coin each.\n * Aoki removes the coin from Vertex 2. Now, Vertex 2 contains one coin.\n * Takahashi removes the coin from Vertex 2. Now, there is no coin remaining on the tree.\n * Aoki takes his turn when there is no coin on the tree and loses.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 2 4\n 4 6\n 5 6", "output": "Second\n \n\n* * *"}, {"input": "7\n 1 7\n 7 4\n 3 4\n 7 5\n 6 3\n 2 1", "output": "First"}] |
Print `First` if Takahashi will win, and print `Second` if Aoki will win.
* * * | s351353093 | Accepted | p03055 | Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_{N-1} b_{N-1} | N = int(input())
if N == 1:
print("First")
exit()
ab = [list(map(int, input().split())) for _ in range(N - 1)]
R = {}
for a, b in ab:
if a - 1 in R:
R[a - 1].append(b - 1)
else:
R[a - 1] = [b - 1]
if b - 1 in R:
R[b - 1].append(a - 1)
else:
R[b - 1] = [a - 1]
L = [0] * N
L[0] = 1
F = []
RL = {}
RL[1] = [0]
RL[2] = []
for i in R[0]:
F.append(i)
L[i] = 2
RL[2].append(i)
k = 2
while F != []:
k += 1
Ft = []
RL[k] = []
for i in F:
for j in R[i]:
if L[j] == 0:
L[j] = k
Ft.append(j)
RL[k].append(j)
F = Ft
d = 0
D = [0] * N
for i in range(k - 1, 0, -1):
for j in RL[i]:
for k in R[j]:
if L[k] == i - 1:
if D[k] == 0:
D[k] = D[j] + 1
d = max(d, D[j] + 1)
else:
d = max(d, D[j] + D[k] + 1)
D[k] = max(D[k], D[j] + 1)
if d % 3 == 1:
print("Second")
else:
print("First")
| Statement
Takahashi and Aoki will play a game on a tree. The tree has N vertices
numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex
b_i.
At the beginning of the game, each vertex contains a coin. Starting from
Takahashi, he and Aoki will alternately perform the following operation:
* Choose a vertex v that contains one or more coins, and remove all the coins from v.
* Then, move each coin remaining on the tree to the vertex that is nearest to v among the adjacent vertices of the coin's current vertex.
The player who becomes unable to play, loses the game. That is, the player who
takes his turn when there is no coin remaining on the tree, loses the game.
Determine the winner of the game when both players play optimally. | [{"input": "3\n 1 2\n 2 3", "output": "First\n \n\nHere is one possible progress of the game:\n\n * Takahashi removes the coin from Vertex 1. Now, Vertex 1 and Vertex 2 contain one coin each.\n * Aoki removes the coin from Vertex 2. Now, Vertex 2 contains one coin.\n * Takahashi removes the coin from Vertex 2. Now, there is no coin remaining on the tree.\n * Aoki takes his turn when there is no coin on the tree and loses.\n\n* * *"}, {"input": "6\n 1 2\n 2 3\n 2 4\n 4 6\n 5 6", "output": "Second\n \n\n* * *"}, {"input": "7\n 1 7\n 7 4\n 3 4\n 7 5\n 6 3\n 2 1", "output": "First"}] |
For each dataset, output a single line containing an integer which is the
value of the given expression. | s239537708 | Accepted | p01087 | The input consists of multiple datasets. Each dataset starts with a line
containing a positive integer _n_ , followed by _n_ lines denoting a single
expression in Dr. Tsukuba's notation.
You may assume that, in the expressions given in the input, every integer
comprises a single digit and that every expression has no more than nine
integers. You may also assume that all the input expressions are valid in the
Dr. Tsukuba's notation. The input contains no extra characters, such as spaces
or empty lines.
The last dataset is immediately followed by a line with a single zero. | while True:
n = int(input())
if n == 0:
break
w = [input() for _ in range(n)]
w = reversed(w)
eles = [[] for _ in range(9)]
for item in w:
d, c = len(item) - 1, item[-1]
if c == "+":
eles[d].append(sum(eles[d + 1]))
eles[d + 1] = []
elif c == "*":
tmp = 1
for i in eles[d + 1]:
tmp *= i
eles[d].append(tmp)
eles[d + 1] = []
else:
eles[d].append(int(c))
print(eles[0][0])
| ICPC Calculator
In mathematics, we usually specify the order of operations by using
parentheses. For example, 7 × (3 + 2) always means multiplying 7 by the result
of 3 + 2 and never means adding 2 to the result of 7 × 3. However, there are
people who do not like parentheses. International Counter of Parentheses
Council (ICPC) is attempting to make a notation without parentheses the world
standard. They are always making studies of such no-parentheses notations.
Dr. Tsukuba, a member of ICPC, invented a new parenthesis-free notation. In
his notation, a single expression is represented by multiple lines, each of
which contains an addition operator (+), a multiplication operator (*) or an
integer. An expression is either a single integer or an operator application
to _operands._ Integers are denoted in decimal notation in one line. An
operator application is denoted by a line of its operator immediately followed
by lines denoting its two or more operands, each of which is an expression,
recursively. Note that when an operand is an operator application, it
comprises multiple lines.
As expressions may be arbitrarily nested, we have to make it clear which
operator is applied to which operands. For that purpose, each of the
expressions is given its _nesting level._ The top level expression has the
nesting level of 0. When an expression of level _n_ is an operator
application, its operands are expressions of level _n_ \+ 1. The first line of
an expression starts with a sequence of periods (.), the number of which
indicates the level of the expression.
For example, 2 + 3 in the regular mathematics is denoted as in Figure 1. An
operator can be applied to two or more operands. Operators + and * represent
operations of summation of all operands and multiplication of all operands,
respectively. For example, Figure 2 shows an expression multiplying 2, 3, and
4. For a more complicated example, an expression (2 + 3 + 4) × 5 in the
regular mathematics can be expressed as in Figure 3 while (2 + 3) × 4 × 5 can
be expressed as in Figure 4.
+
.2
.3
Figure 1: 2 + 3
*
.2
.3
.4
Figure 2: An expression multiplying 2, 3, and 4
*
.+
..2
..3
..4
.5
Figure 3: (2 + 3 + 4) × 5
*
.+
..2
..3
.4
.5
Figure 4: (2 + 3) × 4 × 5
Your job is to write a program that computes the value of expressions written
in Dr. Tsukuba's notation to help him. | [{"input": "9\n 4\n +\n .1\n .2\n .3\n 9\n +\n .0\n .+\n ..*\n ...1\n ...*\n ....1\n ....2\n ..0\n 10\n +\n .+\n ..6\n ..2\n .+\n ..1\n ..*\n ...7\n ...6\n .3\n 0", "output": "6\n 2\n 54"}] |
For each dataset, output a single line containing an integer which is the
value of the given expression. | s390056250 | Runtime Error | p01087 | The input consists of multiple datasets. Each dataset starts with a line
containing a positive integer _n_ , followed by _n_ lines denoting a single
expression in Dr. Tsukuba's notation.
You may assume that, in the expressions given in the input, every integer
comprises a single digit and that every expression has no more than nine
integers. You may also assume that all the input expressions are valid in the
Dr. Tsukuba's notation. The input contains no extra characters, such as spaces
or empty lines.
The last dataset is immediately followed by a line with a single zero. | while True:
n = int(input())
if n == 0:
break
li = [input() for i in range(n)]
index = 0
def pls(depth):
k = 0
global index
while len(li[index]) > depth and li[index][depth - 1] == ".":
if (not li[index][depth] == "+") and (not li[index][depth] == "*"):
k += int(li[index][depth])
if not index == n - 1:
index += 1
else:
return k
elif li[index][depth] == "+":
index += 1
k += pls(depth + 1)
elif li[index][depth] == "*":
index += 1
k += prd(depth + 1)
else:
return k
def prd(depth):
k = 1
global index
while len(li[index]) > depth and li[index][depth - 1] == ".":
if (not li[index][depth] == "+") and (not li[index][depth] == "*"):
k *= int(li[index][depth])
if not index == n - 1:
index += 1
else:
return k
elif li[index][depth] == "+":
index += 1
k *= pls(depth + 1)
elif li[index][depth] == "*":
index += 1
k *= prd(depth + 1)
else:
return k
if li[0] == "+":
index += 1
print(pls(1))
elif li[0] == "*":
index += 1
print(prd(1))
| ICPC Calculator
In mathematics, we usually specify the order of operations by using
parentheses. For example, 7 × (3 + 2) always means multiplying 7 by the result
of 3 + 2 and never means adding 2 to the result of 7 × 3. However, there are
people who do not like parentheses. International Counter of Parentheses
Council (ICPC) is attempting to make a notation without parentheses the world
standard. They are always making studies of such no-parentheses notations.
Dr. Tsukuba, a member of ICPC, invented a new parenthesis-free notation. In
his notation, a single expression is represented by multiple lines, each of
which contains an addition operator (+), a multiplication operator (*) or an
integer. An expression is either a single integer or an operator application
to _operands._ Integers are denoted in decimal notation in one line. An
operator application is denoted by a line of its operator immediately followed
by lines denoting its two or more operands, each of which is an expression,
recursively. Note that when an operand is an operator application, it
comprises multiple lines.
As expressions may be arbitrarily nested, we have to make it clear which
operator is applied to which operands. For that purpose, each of the
expressions is given its _nesting level._ The top level expression has the
nesting level of 0. When an expression of level _n_ is an operator
application, its operands are expressions of level _n_ \+ 1. The first line of
an expression starts with a sequence of periods (.), the number of which
indicates the level of the expression.
For example, 2 + 3 in the regular mathematics is denoted as in Figure 1. An
operator can be applied to two or more operands. Operators + and * represent
operations of summation of all operands and multiplication of all operands,
respectively. For example, Figure 2 shows an expression multiplying 2, 3, and
4. For a more complicated example, an expression (2 + 3 + 4) × 5 in the
regular mathematics can be expressed as in Figure 3 while (2 + 3) × 4 × 5 can
be expressed as in Figure 4.
+
.2
.3
Figure 1: 2 + 3
*
.2
.3
.4
Figure 2: An expression multiplying 2, 3, and 4
*
.+
..2
..3
..4
.5
Figure 3: (2 + 3 + 4) × 5
*
.+
..2
..3
.4
.5
Figure 4: (2 + 3) × 4 × 5
Your job is to write a program that computes the value of expressions written
in Dr. Tsukuba's notation to help him. | [{"input": "9\n 4\n +\n .1\n .2\n .3\n 9\n +\n .0\n .+\n ..*\n ...1\n ...*\n ....1\n ....2\n ..0\n 10\n +\n .+\n ..6\n ..2\n .+\n ..1\n ..*\n ...7\n ...6\n .3\n 0", "output": "6\n 2\n 54"}] |
For each dataset, output a single line containing an integer which is the
value of the given expression. | s840969692 | Wrong Answer | p01087 | The input consists of multiple datasets. Each dataset starts with a line
containing a positive integer _n_ , followed by _n_ lines denoting a single
expression in Dr. Tsukuba's notation.
You may assume that, in the expressions given in the input, every integer
comprises a single digit and that every expression has no more than nine
integers. You may also assume that all the input expressions are valid in the
Dr. Tsukuba's notation. The input contains no extra characters, such as spaces
or empty lines.
The last dataset is immediately followed by a line with a single zero. | def calc(p, nums):
if p == "+":
ans = sum(nums)
else:
ans = 1
for i in nums:
ans *= i
return ans
while True:
n = int(input())
if n == 0:
quit()
w = []
depth = 0
for i in range(n):
t = input()
td = t.count(".")
tc = t.replace(".", "")
if tc.isdigit():
tc = int(tc)
else:
td += 1
w.append([td, tc])
depth = max(depth, td)
# while len(w) != 1:
while depth > 0:
# print(w)
for i in range(len(w)):
if w[i][0] == depth:
temp = []
for j in range(i + 1, len(w)):
# print(w[j][1], j)
if w[j][0] == depth and str(w[j][1]).isdigit():
temp.append(w[j][1])
# print(w[i][1], temp)
ta = calc(w[i][1], temp)
# print(ta)
if j >= len(w):
w = w[:i] + [[depth - 1, ta]]
else:
w = w[:i] + [[depth - 1, ta]] + w[j:]
# w = w[:i] + w[depth, ta] + w[j:]
break
depth -= 1
print(w[0][1])
| ICPC Calculator
In mathematics, we usually specify the order of operations by using
parentheses. For example, 7 × (3 + 2) always means multiplying 7 by the result
of 3 + 2 and never means adding 2 to the result of 7 × 3. However, there are
people who do not like parentheses. International Counter of Parentheses
Council (ICPC) is attempting to make a notation without parentheses the world
standard. They are always making studies of such no-parentheses notations.
Dr. Tsukuba, a member of ICPC, invented a new parenthesis-free notation. In
his notation, a single expression is represented by multiple lines, each of
which contains an addition operator (+), a multiplication operator (*) or an
integer. An expression is either a single integer or an operator application
to _operands._ Integers are denoted in decimal notation in one line. An
operator application is denoted by a line of its operator immediately followed
by lines denoting its two or more operands, each of which is an expression,
recursively. Note that when an operand is an operator application, it
comprises multiple lines.
As expressions may be arbitrarily nested, we have to make it clear which
operator is applied to which operands. For that purpose, each of the
expressions is given its _nesting level._ The top level expression has the
nesting level of 0. When an expression of level _n_ is an operator
application, its operands are expressions of level _n_ \+ 1. The first line of
an expression starts with a sequence of periods (.), the number of which
indicates the level of the expression.
For example, 2 + 3 in the regular mathematics is denoted as in Figure 1. An
operator can be applied to two or more operands. Operators + and * represent
operations of summation of all operands and multiplication of all operands,
respectively. For example, Figure 2 shows an expression multiplying 2, 3, and
4. For a more complicated example, an expression (2 + 3 + 4) × 5 in the
regular mathematics can be expressed as in Figure 3 while (2 + 3) × 4 × 5 can
be expressed as in Figure 4.
+
.2
.3
Figure 1: 2 + 3
*
.2
.3
.4
Figure 2: An expression multiplying 2, 3, and 4
*
.+
..2
..3
..4
.5
Figure 3: (2 + 3 + 4) × 5
*
.+
..2
..3
.4
.5
Figure 4: (2 + 3) × 4 × 5
Your job is to write a program that computes the value of expressions written
in Dr. Tsukuba's notation to help him. | [{"input": "9\n 4\n +\n .1\n .2\n .3\n 9\n +\n .0\n .+\n ..*\n ...1\n ...*\n ....1\n ....2\n ..0\n 10\n +\n .+\n ..6\n ..2\n .+\n ..1\n ..*\n ...7\n ...6\n .3\n 0", "output": "6\n 2\n 54"}] |
If the gifts are worth Y yen in total, print the value Y (not necessarily an
integer).
Output will be judged correct when the absolute or relative error from the
judge's output is at most 10^{-5}.
* * * | s420541519 | Wrong Answer | p03110 | Input is given from Standard Input in the following format:
N
x_1 u_1
x_2 u_2
:
x_N u_N | N = input()
| Statement
Takahashi received _otoshidama_ (New Year's money gifts) from N of his
relatives.
You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as
input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the
content of the otoshidama from the i-th relative.
For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first
relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the
otoshidama from the second relative is 0.1 bitcoins.
If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC,
how much are the gifts worth in total? | [{"input": "2\n 10000 JPY\n 0.10000000 BTC", "output": "48000.0\n \n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the\nsecond relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at\nthe rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as `48000` and `48000.1` will also be judged correct.\n\n* * *"}, {"input": "3\n 100000000 JPY\n 100.00000000 BTC\n 0.00000001 BTC", "output": "138000000.0038\n \n\nIn this case, outputs such as `138001000` and `1.38e8` will also be judged\ncorrect."}] |
If the gifts are worth Y yen in total, print the value Y (not necessarily an
integer).
Output will be judged correct when the absolute or relative error from the
judge's output is at most 10^{-5}.
* * * | s798357201 | Wrong Answer | p03110 | Input is given from Standard Input in the following format:
N
x_1 u_1
x_2 u_2
:
x_N u_N | # お年玉の合計を記録する変数
moneyTotal = 0
# お年玉を貰った数を入力
moneyCount = int(input())
# 受け取った数だけ入力を受け付ける
for i in range(moneyCount):
# 金額と単位で入力
money = input()
# 金額と単位を分割
moneyInfo = money.split()
# 金額取得
moneyAmount = moneyInfo[0]
# 単位取得
moneyUnit = moneyInfo[1]
if moneyUnit == "JPY":
# 日本円で合計値を加算
moneyTotal += int(moneyAmount)
if moneyUnit == "BTC":
# 1BTC = 380000.0円で加算
moneyTotal += int(float(moneyAmount) * 380000.0)
print(moneyTotal)
| Statement
Takahashi received _otoshidama_ (New Year's money gifts) from N of his
relatives.
You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as
input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the
content of the otoshidama from the i-th relative.
For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first
relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the
otoshidama from the second relative is 0.1 bitcoins.
If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC,
how much are the gifts worth in total? | [{"input": "2\n 10000 JPY\n 0.10000000 BTC", "output": "48000.0\n \n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the\nsecond relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at\nthe rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as `48000` and `48000.1` will also be judged correct.\n\n* * *"}, {"input": "3\n 100000000 JPY\n 100.00000000 BTC\n 0.00000001 BTC", "output": "138000000.0038\n \n\nIn this case, outputs such as `138001000` and `1.38e8` will also be judged\ncorrect."}] |
If the gifts are worth Y yen in total, print the value Y (not necessarily an
integer).
Output will be judged correct when the absolute or relative error from the
judge's output is at most 10^{-5}.
* * * | s492669865 | Accepted | p03110 | Input is given from Standard Input in the following format:
N
x_1 u_1
x_2 u_2
:
x_N u_N | _, *t = open(0)
print(sum(38e4 ** ("B" in s) * float(s[:-4]) for s in t))
| Statement
Takahashi received _otoshidama_ (New Year's money gifts) from N of his
relatives.
You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as
input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the
content of the otoshidama from the i-th relative.
For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first
relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the
otoshidama from the second relative is 0.1 bitcoins.
If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC,
how much are the gifts worth in total? | [{"input": "2\n 10000 JPY\n 0.10000000 BTC", "output": "48000.0\n \n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the\nsecond relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at\nthe rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as `48000` and `48000.1` will also be judged correct.\n\n* * *"}, {"input": "3\n 100000000 JPY\n 100.00000000 BTC\n 0.00000001 BTC", "output": "138000000.0038\n \n\nIn this case, outputs such as `138001000` and `1.38e8` will also be judged\ncorrect."}] |
If the gifts are worth Y yen in total, print the value Y (not necessarily an
integer).
Output will be judged correct when the absolute or relative error from the
judge's output is at most 10^{-5}.
* * * | s776673549 | Accepted | p03110 | Input is given from Standard Input in the following format:
N
x_1 u_1
x_2 u_2
:
x_N u_N | n = int(input())
xu_list = [input().split() for _ in range(n)]
print(sum([int(x) if u == "JPY" else float(x) * 380000 for x, u in xu_list]))
| Statement
Takahashi received _otoshidama_ (New Year's money gifts) from N of his
relatives.
You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as
input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the
content of the otoshidama from the i-th relative.
For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first
relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the
otoshidama from the second relative is 0.1 bitcoins.
If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC,
how much are the gifts worth in total? | [{"input": "2\n 10000 JPY\n 0.10000000 BTC", "output": "48000.0\n \n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the\nsecond relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at\nthe rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as `48000` and `48000.1` will also be judged correct.\n\n* * *"}, {"input": "3\n 100000000 JPY\n 100.00000000 BTC\n 0.00000001 BTC", "output": "138000000.0038\n \n\nIn this case, outputs such as `138001000` and `1.38e8` will also be judged\ncorrect."}] |
If the gifts are worth Y yen in total, print the value Y (not necessarily an
integer).
Output will be judged correct when the absolute or relative error from the
judge's output is at most 10^{-5}.
* * * | s373311486 | Accepted | p03110 | Input is given from Standard Input in the following format:
N
x_1 u_1
x_2 u_2
:
x_N u_N | n = int(input())
gifts = [list(input().split()) for _ in range(n)]
gifts = [float(x) if u == "JPY" else float(x) * 380000.0 for x, u in gifts]
print(sum(gifts))
| Statement
Takahashi received _otoshidama_ (New Year's money gifts) from N of his
relatives.
You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as
input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the
content of the otoshidama from the i-th relative.
For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first
relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the
otoshidama from the second relative is 0.1 bitcoins.
If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC,
how much are the gifts worth in total? | [{"input": "2\n 10000 JPY\n 0.10000000 BTC", "output": "48000.0\n \n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the\nsecond relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at\nthe rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as `48000` and `48000.1` will also be judged correct.\n\n* * *"}, {"input": "3\n 100000000 JPY\n 100.00000000 BTC\n 0.00000001 BTC", "output": "138000000.0038\n \n\nIn this case, outputs such as `138001000` and `1.38e8` will also be judged\ncorrect."}] |
If the gifts are worth Y yen in total, print the value Y (not necessarily an
integer).
Output will be judged correct when the absolute or relative error from the
judge's output is at most 10^{-5}.
* * * | s822951258 | Wrong Answer | p03110 | Input is given from Standard Input in the following format:
N
x_1 u_1
x_2 u_2
:
x_N u_N | print(
sum(616.441400297**2 ** ("B" in i) * float(i[:-4]) for i in open(0).readlines()[1:])
)
| Statement
Takahashi received _otoshidama_ (New Year's money gifts) from N of his
relatives.
You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as
input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the
content of the otoshidama from the i-th relative.
For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first
relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the
otoshidama from the second relative is 0.1 bitcoins.
If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC,
how much are the gifts worth in total? | [{"input": "2\n 10000 JPY\n 0.10000000 BTC", "output": "48000.0\n \n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the\nsecond relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at\nthe rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as `48000` and `48000.1` will also be judged correct.\n\n* * *"}, {"input": "3\n 100000000 JPY\n 100.00000000 BTC\n 0.00000001 BTC", "output": "138000000.0038\n \n\nIn this case, outputs such as `138001000` and `1.38e8` will also be judged\ncorrect."}] |
Print the answer.
* * * | s955616369 | Accepted | p03813 | The input is given from Standard Input in the following format:
x | #!/usr/bin/env python3
import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random # random, uniform, randint, randrange, shuffle, sample
# import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate # accumulate(iter[, f])
# from operator import itemgetter # itemgetter(1), itemgetter('key')
# from fractions import gcd # for Python 3.4 (previous contest @AtCoder)
def main():
mod = 1000000007 # 10^9+7
inf = float("inf") # sys.float_info.max = 1.79...e+308
# inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input():
return sys.stdin.readline().rstrip()
def ii():
return int(input())
def mi():
return map(int, input().split())
def mi_0():
return map(lambda x: int(x) - 1, input().split())
def lmi():
return list(map(int, input().split()))
def lmi_0():
return list(map(lambda x: int(x) - 1, input().split()))
def li():
return list(input())
x = ii()
print("ABC") if x < 1200 else print("ARC")
if __name__ == "__main__":
main()
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s389129325 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | input_line = int(input())
if input_line >= 1200
print("ARC")
else
print("ABC") | Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s702592069 | Accepted | p03813 | The input is given from Standard Input in the following format:
x | print("ABC" if (int(input()) < 1200) else "ARC")
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s474047299 | Wrong Answer | p03813 | The input is given from Standard Input in the following format:
x | r = ["ABC", "ARC"]
print(r[int(input()) > 1200])
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s001219213 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | print('A'+'RB'[input()[:2]<’12’]+'C') | Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s474412171 | Wrong Answer | p03813 | The input is given from Standard Input in the following format:
x | 2000
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s971234758 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | print("ABC" if input() < 1200 else "ARC")
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s513013833 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | rate = int(input())
if rate < 1200:
print("ABC")
else:
print("ARC) | Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s964469364 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | N = input()
A = input()
print(len(set(A.split())))
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s660885739 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | x = int(input())
if x < 1200:
print('ABC')
else:
print('ARC') | Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s125597182 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | n = int(input)
if n<1200:
print("ABC")
else:
print("ARC") | Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s361864716 | Accepted | p03813 | The input is given from Standard Input in the following format:
x | print("ABC" if (lambda x=int(input()): True if x < 1200 else False)() else "ARC")
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s260320077 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | s = list(input())
a = []
z = []
for num in range(len(s)):
if s[num] == "A":
a.append(num)
if s[num] == "Z":
z.append(num)
print(max(z) - min(a) + 1)
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s239123004 | Accepted | p03813 | The input is given from Standard Input in the following format:
x | print("AARBCC"[input() < "1200" :: 2])
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s109415207 | Wrong Answer | p03813 | The input is given from Standard Input in the following format:
x | print("AABRCC"[int(input()) // 1200 :: 2])
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s696430688 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | x = int(input())
if x< 1200;
print("ABC")
else:
print("ARC")
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s476709843 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | print(“ABC” if int(input()) <=1200 else(“ARC”)) | Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s785956437 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | print("ABC"(int(input()) < 1200) or "ARC")
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s484910599 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | -*- coding: utf-8 -*-
import sys
import subprocess
import json
import time
import math
import re
import sqlite3
s = input()
print(1)
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s325298432 | Wrong Answer | p03813 | The input is given from Standard Input in the following format:
x | s = list(input())
cnt = 0
i = 0
j = len(s) - 1
for t in range(len(s)):
if s[t] == "A":
break
i += 1
for t in range(len(s)):
if s[j] == "Z":
break
j -= 1
print(j - i + 1)
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s165691185 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | a = int(input())
if a >= 1200:
print("ARC");
else:
print("ABC"); | Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s464923968 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | N = int(input())
A = list(map(int, input().split()))
dict1 = {}
for i in range(N):
if A[i] not in dict1.keys():
dict1[A[i]] = 0
else:
dict1[A[i]] += 1
value1 = []
for value in dict1.values():
value1.append(value)
value2 = sorted(value1, reverse=True)
if value2[0] - value2[1] >= sum(value2[1:]):
print(N - (value2[0] * 2))
else:
if sum(value2[0:]) % 2 == 0:
print(len(value2))
else:
if len(value2) != 0:
print(len(value2) - 1)
else:
print(1)
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s378024262 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | import sys, os
f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
sys.stdin = open('./input.txt', 'r')
def solve():
x = f()[0]
if x >= 1200:
print("ARC")
else print("ABC")
solve()
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s209275739 | Wrong Answer | p03813 | The input is given from Standard Input in the following format:
x | import math
x = int(input())
count = 0
buff = x
count = buff // 11
_buff = buff % 11
me = buff // 5.5
_fo = me / 2
_ba = me / 2
se = x - me * 5.5
if se >= 7:
print(int(buff // 5.5 + 2))
exit()
elif 7 > se and se > 0:
print(int(buff // 5.5 + 1))
exit()
print(int(buff // 5.5))
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s091933039 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | def start(l):
for i in range(1, l - 1):
if S_list[i] == "A":
return i + 1
def finish(l):
for i in range(1, l - 1):
if S_list[l - i] == "Z":
return l - i + 1
S_list = list(input())
l = len(S_list)
print(finish(l) - start(l) + 1)
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s661965705 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | x=int(input(" :")
if x<1200:
print("ABC")
else:
print("ARC")
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Print the answer.
* * * | s079741032 | Runtime Error | p03813 | The input is given from Standard Input in the following format:
x | #include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <limits>
using namespace std;
typedef long long ll;
float inf = std::numeric_limits<float>::infinity();
ll mod = 1e9+7;
/* 二次元配列の宣言
vector<vector<int>> tb;
tb.resize(H);
for (size_t i = 0; i < H; i++) {
tb[i].resize(W);
}
*/
/*
A.resize(N);
for (int i = 0; i < N; i++) {scanf("%d",&A[i]);}
*/
int main(void) {
int x;
cin >> x;
if (x<1200){
printf("ABC");
}else{
printf("ARC");
}
}
| Statement
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his
current rating is less than 1200, and participate in AtCoder Regular Contest
(ARC) otherwise.
You are given Smeke's current rating, x. Print `ABC` if Smeke will participate
in ABC, and print `ARC` otherwise. | [{"input": "1000", "output": "ABC\n \n\nSmeke's current rating is less than 1200, thus the output should be `ABC`.\n\n* * *"}, {"input": "2000", "output": "ARC\n \n\nSmeke's current rating is not less than 1200, thus the output should be `ARC`."}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.