Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term. Constraints * 2 ≤ n ≤ 10^5 * |a_i| ≤ 10^9 * Each a_i is an integer. Input Input is given from Standard Input in the following format: n a_1 a_2 ... a_n Output Print the minimum necessary count of operations. Examples Input 4 1 -3 1 0 Output 4 Input 5 3 -6 4 -5 7 Output 0 Input 6 -1 4 3 2 -5 4 Output 8
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
def c(ints): for i in range(len(ints)): if ints[i] != 0: sig = 1 if ints[i] > 0 else -1 total = ints[i] mov = i j = i break if i == len(ints) - 1: return i + 1 for i_ in ints[j+1:]: tmp = total + i_ if tmp == 0: mov +=1 tmp = -sig elif sig * tmp > 0: mov += abs(tmp) + 1 tmp = -sig sig *= -1 total = tmp return mov _ = input() inp = input() inp = inp.split(' ') inp = [int(i_) for i_ in inp] print(c(inp))
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; class Main{ static void solve(){ int x = ni(); double p = ni()/100.0; double ans = 0; if(x%2==0)ans=(double)x/(2*p); else{ ans=1; ans += (x-1)/2; ans += ((1-p)*((double)x+1))/(p*2); } out.println(ans); } public static void main(String[] args){ solve(); out.flush(); } private static InputStream in = System.in; private static PrintWriter out = new PrintWriter(System.out); static boolean inrange(int y, int x, int h, int w){ return y>=0 && y<h && x>=0 && x<w; } @SuppressWarnings("unchecked") static<T extends Comparable> int lower_bound(List<T> list, T key){ int lower=-1;int upper=list.size(); while(upper - lower>1){ int center =(upper+lower)/2; if(list.get(center).compareTo(key)>=0)upper=center; else lower=center; } return upper; } @SuppressWarnings("unchecked") static <T extends Comparable> int upper_bound(List<T> list, T key){ int lower=-1;int upper=list.size(); while(upper-lower >1){ int center=(upper+lower)/2; if(list.get(center).compareTo(key)>0)upper=center; else lower=center; } return upper; } @SuppressWarnings("unchecked") static <T extends Comparable> boolean next_permutation(List<T> list){ int lastIndex = list.size()-2; while(lastIndex>=0 && list.get(lastIndex).compareTo(list.get(lastIndex+1))>=0)--lastIndex; if(lastIndex<0)return false; int swapIndex = list.size()-1; while(list.get(lastIndex).compareTo(list.get(swapIndex))>=0)swapIndex--; T tmp = list.get(lastIndex); list.set(lastIndex++, list.get(swapIndex)); list.set(swapIndex, tmp); swapIndex = list.size()-1; while(lastIndex<swapIndex){ tmp = list.get(lastIndex); list.set(lastIndex, list.get(swapIndex)); list.set(swapIndex, tmp); ++lastIndex;--swapIndex; } return true; } private static final byte[] buffer = new byte[1<<15]; private static int ptr = 0; private static int buflen = 0; private static boolean hasNextByte(){ if(ptr<buflen)return true; ptr = 0; try{ buflen = in.read(buffer); } catch (IOException e){ e.printStackTrace(); } return buflen>0; } private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} private static double nd(){ return Double.parseDouble(ns()); } private static char nc(){ return (char)skip(); } private static String ns(){ StringBuilder sb = new StringBuilder(); for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); return sb.toString(); } private static int[] nia(int n){ int[] res = new int[n]; for(int i=0;i<n;++i)res[i]=ni(); return res; } private static long[] nla(int n){ long[] res = new long[n]; for(int i=0;i<n;++i)res[i]=nl(); return res; } private static int ni(){ int res=0,b; boolean minus=false; while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); if(b=='-'){ minus=true; b=readByte(); } for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); return minus ? -res:res; } private static long nl(){ long res=0,b; boolean minus=false; while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); if(b=='-'){ minus=true; b=readByte(); } for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); return minus ? -res:res; } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i)) #define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<int, lint> pil; typedef pair<lint, lint> pll; 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;} template<class T> T div_floor(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>=0 ? a/b : (a+1)/b-1; } template<class T> T div_ceil(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>0 ? (a-1)/b+1 : a/b; } constexpr lint mod = 1e9+7; constexpr lint INF = mod * mod; constexpr int MAX = 100010; double p; double E(int d){ if(d % 2 == 1) return 1 + p*E(d-1) + (1-p)*E(d+1); else return 1/p * d/2; } int main(){ int x, t; scanf("%d%d", &x, &t); p = 1.0*t / 100; printf("%.20lf\n", E(x)); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() typedef long long ll; void solve() { int n; double p; cin >> n >> p; p = p / 100.0; n = (n + 1) / 2; cout << double(n) / p; } // CHECK LIMITS (n <= 10^5) // CHECK CORNER CASES (n == 1) int main() { ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); cout.setf(ios::fixed), cout.precision(20); //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl; solve(); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
python3
#!/usr/bin/env python3 import math x = int(input()) p = int(input())/100 print(math.ceil(x / 2) / p)
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
java
public class Main { private static void solve() { long x = nl(); double p = nd() / 100; double ret = 0; if (x % 2 == 0) { ret = f(x, p); } else { ret = (f(x - 1, p) * p + f(x + 1, p) * (1.0 - p)) + 1; } System.out.println(ret); } private static double f(long x, double p) { return x / p / 2; } public static void main(String[] args) { new Thread(null, new Runnable() { @Override public void run() { long start = System.currentTimeMillis(); String debug = args.length > 0 ? args[0] : null; if (debug != null) { try { is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug)); } catch (Exception e) { throw new RuntimeException(e); } } reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768); solve(); out.flush(); tr((System.currentTimeMillis() - start) + "ms"); } }, "", 64000000).start(); } private static java.io.InputStream is = System.in; private static java.io.PrintWriter out = new java.io.PrintWriter(System.out); private static java.util.StringTokenizer tokenizer = null; private static java.io.BufferedReader reader; public static String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new java.util.StringTokenizer(reader.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private static double nd() { return Double.parseDouble(next()); } private static long nl() { return Long.parseLong(next()); } private static int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private static char[] ns() { return next().toCharArray(); } private static long[] nal(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } private static int[][] ntable(int n, int m) { int[][] table = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { table[i][j] = ni(); } } return table; } private static int[][] nlist(int n, int m) { int[][] table = new int[m][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { table[j][i] = ni(); } } return table; } private static int ni() { return Integer.parseInt(next()); } private static void tr(Object... o) { if (is != System.in) System.out.println(java.util.Arrays.deepToString(o)); } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> #define FOR(i, n, m) for(int i = n; i < (int)m; i++) #define REP(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define pb push_back using namespace std; using ll = std::int_fast64_t; using ld = long double; using P = pair<ll, ll>; constexpr ll inf = 1000000000; constexpr ll mod = 1000000007; constexpr long double eps = 1e-15; template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> p) { os << to_string(p.first) << " " << to_string(p.second); return os; } template<typename T> ostream& operator<<(ostream& os, vector<T>& v) { REP(i, v.size()) { if(i) os << " "; os << to_string(v[i]); } return os; } /* template<typename T> struct Treap { double drand() { // random number in [0, 1] static random_device rd; static mt19937 mt(rd()); return (unsigned)mt() / (double)numeric_limits<unsigned>::max(); } T v; double p; int cnt; Treap* lch; Treap* rch; Treap(T v) : v(v), p(drand()), cnt(1), lch(NULL), rch(NULL) { } Treap* update() { this->size = size(this->lch) + size(this->rch) + 1; return this; } static int size(Treap* t) { if(!t) return 0; else return t->cnt; } static Treap* merge(Treap* l, Treap* r) { if(!l || !r) { if(!l) return r; else return l; } if(l->p >= r->p) { l->rch = merge(l->rch, r); return l->update(); } else { r->lch = merge(r->lch, l); return r->update(); } } static pair<Treap*, Treap*> split(Treap* t, int k) { // split [0, k) and [k, n) if(k == 0) return {NULL, t}; if(!(t->l)) { auto tmp = split(t->r, k - 1); t->r = tmp.first; return {t->update(), tmp.second}; } else if(!(t->r)) { auto tmp = split(t->r, k - 1); t->r = tmp.first; return {t->update(), tmp.second}; } else { } } Treap* insert() { } Treap* erase() { } T operator[](int k) { } }; */ int main() { cin.tie(0); ios::sync_with_stdio(false); int x, p; cin >> x >> p; ld ans = 0; if(x % 2) { ans += 1; ans += p / (ld)100 * (100 / (ld)p * ((x - 1) / 2)) + (100 - p) / (ld)100 * (100 / (ld)p * ((x + 1) / 2)); } else { ans = 100 / (ld)p * (x / 2); } cout << fixed << setprecision(39) << ans << endl; return 0; } // ---------------------------------------
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
//todo 文字数を少なくする //#pragma GCC optimize ("-O3") #include <bits/stdc++.h> using namespace std; //@起動時 struct initon { initon() { cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); srand((unsigned) clock() + (unsigned) time(NULL)); }; } __initon; //衝突対策 #define ws ___ws //@必須構造 struct T { int f, s, t; T() { f = -1, s = -1, t = -1; } T(int f, int s, int t) : f(f), s(s), t(t) {} bool operator<(const T &r) const { return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t; //return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順 } bool operator>(const T &r) const { return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; //return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順 } bool operator==(const T &r) const { return f == r.f && s == r.s && t == r.t; } bool operator!=(const T &r) const { return f != r.f || s != r.s || t != r.t; } int operator[](int i) { assert(i < 3); return i == 0 ? f : i == 1 ? s : t; } }; struct F { int a, b, c, d; F() { a = -1, b = -1, c = -1, d = -1; } F(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {} bool operator<(const F &r) const { return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d; // return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d; } bool operator>(const F &r) const { return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d; // return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d; } bool operator==(const F &r) const { return a == r.a && b == r.b && c == r.c && d == r.d; } bool operator!=(const F &r) const { return a != r.a || b != r.b || c != r.c || d != r.d; } int operator[](int i) { assert(i < 4); return i == 0 ? a : i == 1 ? b : i == 2 ? c : d; } }; T mt(int a, int b, int c) { return T(a, b, c); } //@マクロ省略系 型,構造 #define int long long #define ll long long #define double long double #define ull unsigned long long using dou = double; using itn = int; using str = string; using bo= bool; #define au auto using P = pair<ll, ll>; #define fi first #define se second #define vec vector #define beg begin #define rbeg rbegin #define con continue #define bre break #define brk break #define is == //マクロ省略系 コンテナ using vi = vector<int>; #define _overloadvvi(_1, _2, _3, _4, name, ...) name #define vvi0() vec<vi> #define vvi1(a) vec<vi> a #define vvi2(a, b) vec<vi> a(b) #define vvi3(a, b, c) vec<vi> a(b,vi(c)) #define vvi4(a, b, c, d) vec<vi> a(b,vi(c,d)) #define vvi(...) _overloadvvi(__VA_ARGS__,vvi4,vvi3,vvi2 ,vvi1,vvi0)(__VA_ARGS__) using vl = vector<ll>; #define _overloadvvl(_1, _2, _3, _4, name, ...) name #define vvl1(a) vec<vl> a #define vvl2(a, b) vec<vl> a(b) #define vvl3(a, b, c) vec<vl> a(b,vl(c)) #define vvl4(a, b, c, d) vec<vl> a(b,vl(c,d)) #define vvl(...) _overloadvvl(__VA_ARGS__,vvl4,vvl3,vvl2 ,vvl1)(__VA_ARGS__) using vb = vector<bool>; #define _overloadvvb(_1, _2, _3, _4, name, ...) name #define vvb1(a) vec<vb> a #define vvb2(a, b) vec<vb> a(b) #define vvb3(a, b, c) vec<vb> a(b,vb(c)) #define vvb4(a, b, c, d) vec<vb> a(b,vb(c,d)) #define vvb(...) _overloadvvb(__VA_ARGS__,vvb4,vvb3,vvb2 ,vvb1)(__VA_ARGS__) using vs = vector<string>; #define _overloadvvs(_1, _2, _3, _4, name, ...) name #define vvs1(a) vec<vs> a #define vvs2(a, b) vec<vs> a(b) #define vvs3(a, b, c) vec<vs> a(b,vs(c)) #define vvs4(a, b, c, d) vec<vs> a(b,vs(c,d)) #define vvs(...) _overloadvvs(__VA_ARGS__,vvs4,vvs3,vvs2 ,vvs1)(__VA_ARGS__) using vd = vector<double>; #define _overloadvvd(_1, _2, _3, _4, name, ...) name #define vvd1(a) vec<vd> a #define vvd2(a, b) vec<vd> a(b) #define vvd3(a, b, c) vec<vd> a(b,vd(c)) #define vvd4(a, b, c, d) vec<vd> a(b,vd(c,d)) #define vvd(...) _overloadvvd(__VA_ARGS__,vvd4,vvd3,vvd2 ,vvd1)(__VA_ARGS__) using vc=vector<char>; #define _overloadvvc(_1, _2, _3, _4, name, ...) name #define vvc1(a) vec<vc> a #define vvc2(a, b) vec<vc> a(b) #define vvc3(a, b, c) vec<vc> a(b,vc(c)) #define vvc4(a, b, c, d) vec<vc> a(b,vc(c,d)) #define vvc(...) _overloadvvc(__VA_ARGS__,vvc4,vvc3,vvc2 ,vvc1)(__VA_ARGS__) using vp = vector<P>; #define _overloadvvp(_1, _2, _3, _4, name, ...) name #define vvp1(a) vec<vp> a #define vvp2(a, b) vec<vp> a(b) #define vvp3(a, b, c) vec<vp> a(b,vp(c)) #define vvp4(a, b, c, d) vec<vp> a(b,vp(c,d)) using vt = vector<T>; #define _overloadvvt(_1, _2, _3, _4, name, ...) name #define vvt1(a) vec<vt> a #define vvt2(a, b) vec<vt> a(b) #define vvt3(a, b, c) vec<vt> a(b,vt(c)) #define vvt4(a, b, c, d) vec<vt> a(b,vt(c,d)) #define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d))) #define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d))) #define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d))) #define _vvi vector<vi> #define _vvl vector<vl> #define _vvb vector<vb> #define _vvs vector<vs> #define _vvd vector<vd> #define _vvc vector<vc> #define _vvp vector<vp> #define PQ priority_queue<ll, vector<ll>, greater<ll> > #define tos to_string using mapi = map<int, int>; using mapd = map<dou, int>; using mapc = map<char, int>; using maps = map<str, int>; using seti = set<int>; using setd = set<dou>; using setc = set<char>; using sets = set<str>; using qui = queue<int>; #define bset bitset #define uset unordered_set #define mset multiset #define umap unordered_map #define umapi unordered_map<int,int> #define umapp unordered_map<P,int> #define mmap multimap //マクロ 繰り返し #define _overloadrep(_1, _2, _3, _4, name, ...) name # define _rep(i, n) for(int i = 0,_lim=n; i < _lim ; i++) #define repi(i, m, n) for(int i = m,_lim=n; i < _lim ; i++) #define repadd(i, m, n, ad) for(int i = m,_lim=n; i < _lim ; i+= ad) #define rep(...) _overloadrep(__VA_ARGS__,repadd,repi,_rep,)(__VA_ARGS__) #define _rer(i, n) for(int i = n; i >= 0 ; i--) #define reri(i, m, n) for(int i = m,_lim=n; i >= _lim ; i--) #define rerdec(i, m, n, dec) for(int i = m,_lim=n; i >= _lim ; i-=dec) #define rer(...) _overloadrep(__VA_ARGS__,rerdec,reri,_rer,)(__VA_ARGS__) #define fora(a, b) for(auto&& a : b) #define forg(gi, ve) for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); gi++) #define fort(gi, ve) for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); gi++)if(t!=p) //#define fort(gi, ve) for (int gi = 0, f, t, c;gi<ve.size()&& (gi+= (ve[gi].t==p))< ve.size() && (f = ve[gi].f,t=ve[gi].t, c = ve[gi].c,true); gi++) //マクロ 定数 #define k3 1010 #define k4 10101 #define k5 101010 #define k6 1010101 #define k7 10101010 const int inf = (int) 1e9 + 100; const ll linf = (ll) 1e18 + 100; const double eps = 1e-9; const double PI = 3.1415926535897932384626433832795029L; ll ma = numeric_limits<ll>::min(); ll mi = numeric_limits<ll>::max(); const int y4[] = {-1, 1, 0, 0}; const int x4[] = {0, 0, -1, 1}; const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1}; const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1}; //マクロ省略形 関数等 #define arsz(a) (sizeof(a)/sizeof(a[0])) #define sz(a) ((int)(a).size()) #define rs resize #define mp make_pair #define pb push_back #define pf push_front #define eb emplace_back #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() //@拡張系 こう出来るべきというもの //埋め込み 存在を意識せずに機能を増やされているもの namespace std { template<> class hash<std::pair<signed, signed>> { public: size_t operator()(const std::pair<signed, signed> &x) const { return hash<ll>()(((ll) x.first << 32) + x.second); } }; template<> class hash<std::pair<ll, ll>> { public: //大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断 size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(((ll) x.first << 32) + x.second); } }; } istream &operator>>(istream &iss, P &a) { iss >> a.first >> a.second; return iss; } template<typename T> istream &operator>>(istream &iss, vector<T> &vec) { for (T &x: vec) iss >> x; return iss; } ostream &operator<<(ostream &os, P p) { os << p.fi << " " << p.se << endl; return os; } ostream &operator<<(ostream &os, T p) { os << p.f << " " << p.s << " " << p.t; return os; } ostream &operator<<(ostream &os, F p) { os << p.a << " " << p.b << " " << p.c << " " << p.d; return os; } template<typename T> ostream &operator<<(ostream &os, vector <T> &vec) { for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } template<typename T> ostream &operator<<(ostream &os, vector <vector<T>> &vec) { for (int i = 0; i < vec.size(); i++) { for (int j = 0; j < vec[0].size(); j++) { os << vec[i][j]; } os << endl; } return os; } template<typename V, typename H> void resize(vector<V> &vec, const H head) { vec.resize(head); } template<typename V, typename H, typename ... T> void resize(vector<V> &vec, const H &head, const T ... tail) { vec.resize(head); for (auto &v: vec) resize(v, tail...); } template<typename T, typename _Pr> bool all_of(const vector<T> &vec, _Pr pred) { return std::all_of(vec.begin(), vec.end(), pred); } template<typename T, typename _Pr> bool any_of(const vector<T> &vec, _Pr pred) { return std::any_of(vec.begin(), vec.end(), pred); } template<typename T, typename _Pr> bool none_of(const vector<T> &vec, _Pr pred) { return std::none_of(vec.begin(), vec.end(), pred); } template<typename T, typename _Pr> const typename vector<T>::const_iterator find_if(const vector<T> &vec, _Pr pred) { return std::find_if(vec.begin(), vec.end(), pred); } template<typename T> bool contains(const vector<T> &vec, const T &val) { return std::find(vec.begin(), vec.end(), val) != vec.end(); } template<typename T, typename _Pr> bool contains_if(const vector<T> &vec, _Pr pred) { return std::find_if(vec.begin(), vec.end(), pred) != vec.end(); } template<class T> void replace(vector<T> &a, T key, T v) { replace(a.begin(), a.end(), key, v); } template<class T> bool includes(vector<T> &a, vector<T> &b) { vi c = a; vi d = b; sort(all(c)); sort(all(d)); return includes(all(c), all(d)); } template<class T> bool is_permutation(vector<T> &a, vector<T> &b) { return is_permutation(all(a), all(b)); } template<class T> bool next_permutation(vector<T> &a) { return next_permutation(all(a)); } template<class T> T pop(set<T> &set) { T res = *set.begin(); set.erase(set.find(res)); return res; } template<class T> T pop(mset<T> &set) { T res = *set.begin(); set.erase(set.find(res)); return res; } template<class T> T popBack(set<T> &set) { T res = *set.rbegin(); set.erase(set.find(res)); return res; } template<class T> T popBack(mset<T> &set) { T res = *set.rbegin(); set.erase(set.find(res)); return res; } inline void sort(string &a) { sort(a.begin(), a.end()); } template<class T> inline void sort(vector<T> &a) { sort(a.begin(), a.end()); }; template<class T> inline void sort(vector<T> &a, int len) { sort(a.begin(), a.begin() + len); }; template<class T, class F> inline void sort(vector<T> &a, F f) { sort(a.begin(), a.end(), [&](T l, T r) { return f(l) < f(r); }); }; enum ___pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd }; inline void sort(vector<P> &a, ___pcomparator type) { switch (type) { case fisi: sort(all(a), [&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; }); break; case fisd: sort(all(a), [&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; }); break; case fdsi: sort(all(a), [&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; }); break; case fdsd: sort(all(a), [&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; }); break; case sifi: sort(all(a), [&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; }); break; case sifd: sort(all(a), [&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; }); break; case sdfi: sort(all(a), [&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; }); break; case sdfd: sort(all(a), [&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; }); break; } }; inline void sort(vector<T> &a, ___pcomparator type) { switch (type) { case fisi: sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f < r.f : l.s < r.s; }); break; case fisd: sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f < r.f : l.s > r.s; }); break; case fdsi: sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f > r.f : l.s < r.s; }); break; case fdsd: sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f > r.f : l.s > r.s; }); break; case sifi: sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s < r.s : l.f < r.f; }); break; case sifd: sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s < r.s : l.f > r.f; }); break; case sdfi: sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s > r.s : l.f < r.f; }); break; case sdfd: sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s > r.s : l.f > r.f; }); break; } }; template<class T> inline void rsort(vector<T> &a) { sort(a.begin(), a.end(), greater<T>()); }; template<class T> inline void rsort(vector<T> &a, int len) { sort(a.begin(), a.begin() + len, greater<T>()); }; template<class U, class F> inline void rsort(vector<U> &a, F f) { sort(a.begin(), a.end(), [&](U l, U r) { return f(l) > f(r); }); }; template<class U> inline void sortp(vector<U> &a, vector<U> &b) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); sort(c); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second;; } }; //F = T<T> //例えばreturn p.fi + p.se; template<class U, class F> inline void sortp(vector<U> &a, vector<U> &b, F f) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); sort(c, f); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second; } }; template<class U, class F> inline void sortp(vector<U> &a, vector<U> &b, char type) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); sort(c, type); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second; } }; template<class U> inline void rsortp(vector<U> &a, vector<U> &b) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); rsort(c); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second; } }; template<class U, class F> inline void rsortp(vector<U> &a, vector<U> &b, F f) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); rsort(c, f); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second; } }; template<class U> inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c) { vt r; int n = sz(a); assert(n == sz(b)); assert(n == sz(c)); rep(i, n)r.eb(a[i], b[i], c[i]); sort(r); rep(i, n) { a[i] = r[i].f; b[i] = r[i].s; c[i] = r[i].t; } }; template<class U, class F> inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) { vt r; int n = sz(a); assert(n == sz(b)); assert(n == sz(c)); rep(i, n)r.eb(a[i], b[i], c[i]); sort(r, f); rep(i, n) { a[i] = r[i].f; b[i] = r[i].s; c[i] = r[i].t; } }; template<class U, class F> inline void rsortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) { vt r; int n = sz(a); assert(n == sz(b)); assert(n == sz(c)); rep(i, n)r.eb(a[i], b[i], c[i]); rsort(r, f); rep(i, n) { a[i] = r[i].f; b[i] = r[i].s; c[i] = r[i].t; } }; template<class T> inline void sort2(vector<vector<T>> &a) { for (int i = 0, n = a.size(); i < n; i++)sort(a[i]); } template<class T> inline void rsort2(vector<vector<T>> &a) { for (int i = 0, n = a.size(); i < n; i++)rsort(a[i]); } template<typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) { rep(i, N)a[i] = v; } template<typename A, size_t N, size_t O, typename T> void fill(A (&a)[N][O], const T &v) { rep(i, N)rep(j, O)a[i][j] = v; } template<typename A, size_t N, size_t O, size_t P, typename T> void fill(A (&a)[N][O][P], const T &v) { rep(i, N)rep(j, O)rep(k, P)a[i][j][k] = v; } template<typename A, size_t N, size_t O, size_t P, size_t Q, typename T> void fill(A (&a)[N][O][P][Q], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)a[i][j][k][l] = v; } template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, typename T> void fill(A (&a)[N][O][P][Q][R], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)a[i][j][k][l][m] = v; } template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S, typename T> void fill(A (&a)[N][O][P][Q][R][S], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)a[i][j][k][l][m][n] = v; } template<typename V, typename T> void fill(V &xx, const T vall) { xx = vall; } template<typename V, typename T> void fill(vector<V> &vecc, const T vall) { for (auto &&vx: vecc) fill(vx, vall); } //@汎用便利関数 入力 template<typename T = int> T _in() { T x; cin >> x; return (x); } #define _overloadin(_1, _2, _3, _4, name, ...) name #define in0() _in() #define in1(a) cin>>a #define in2(a, b) cin>>a>>b #define in3(a, b, c) cin>>a>>b>>c #define in4(a, b, c, d) cin>>a>>b>>c>>d #define in(...) _overloadin(__VA_ARGS__,in4,in3,in2 ,in1,in0)(__VA_ARGS__) #define _overloaddin(_1, _2, _3, _4, name, ...) name #define din1(a) int a;cin>>a #define din2(a, b) int a,b;cin>>a>>b #define din3(a, b, c) int a,b,c;cin>>a>>b>>c #define din4(a, b, c, d) int a,b,c,d;cin>>a>>b>>c>>d #define din(...) _overloadin(__VA_ARGS__,din4,din3,din2 ,din1)(__VA_ARGS__) #define _overloaddind(_1, _2, _3, _4, name, ...) name #define din1d(a) int a;cin>>a;a-- #define din2d(a, b) int a,b;cin>>a>>b;a--,b-- #define din3d(a, b, c) int a,b,c;cin>>a>>b>>c;a--,b--,c-- #define din4d(a, b, c, d) int a,b,c,d;cin>>a>>b>>c>>d;;a--,b--,c--,d-- #define dind(...) _overloaddind(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__) #define _overloadout(_1, _2, _3, _4, name, ...) name #define out1(a) cout<<a<<endl #define out2(a, b) cout<<a<<" "<< b<<endl #define out3(a, b, c) cout<<a<<" "<<b<<" "<<c<<endl #define out4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl #define out(...) _overloadout(__VA_ARGS__,out4,out3,out2,out1)(__VA_ARGS__) string sin() { return _in<string>(); } ll lin() { return _in<ll>(); } #define na(a, n) a.resize(n); rep(i,n) cin >> a[i]; #define nao(a, n) a.resize(n+1); rep(i,n) cin >> a[i+1]; #define nad(a, n) a.resize(n); rep(i,n){ cin >> a[i]; a[i]--;} #define na2(a, b, n) a.resize(n),b.resize(n);rep(i, n)cin >> a[i] >> b[i]; #define na2d(a, b, n) a.resize(n),b.resize(n);rep(i, n){cin >> a[i] >> b[i];a[i]--,b[i]--;} #define na3(a, b, c, n) a.resize(n),b.resize(n),c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i]; #define na3d(a, b, c, n) a.resize(n),b.resize(n),c.resize(n); rep(i, n){cin >> a[i] >> b[i] >> c[i];a[i]--,b[i]--,c[i]--;} #define nt(a, h, w) resize(a,h,w);rep(hi,h)rep(wi,w) cin >> a[hi][wi]; #define ntd(a, h, w) rs(a,h,w);rep(hi,h)rep(wi,w) cin >> a[hi][wi], a[hi][wi]--; #define ntp(a, h, w) fill(a,'#');rep(hi,1,h+1)rep(wi,1,w+1) cin >> a[hi][wi]; //デバッグ #define sp << " " << #define debugName(VariableName) # VariableName #define _deb1(x) cerr << debugName(x)<<" = "<<x << endl #define _deb2(x, y) cerr << debugName(x)<<" = "<<x<<", "<< debugName(y)<<" = "<<y<< endl #define _deb3(x, y, z) cerr << debugName(x)<<" = "<<x << ", " << debugName(y)<<" = "<<y <<", " debugName(z)<<" = "<<z <<endl #define _deb4(x, y, z, a) cerr << debugName(x)<<" = "<<x <<", " << debugName(y)<<" = "<<y <<", " << debugName(z)<<" = "<<z <<", " << debugName(a)<<" = "<<a<<endl #define _deb5(x, y, z, a, b) cerr << debugName(x)<<" = "<<x <<", " << debugName(y)<<" = "<<y <<", " << debugName(z)<<" = "<<z <<", " << debugName(a)<<" = "<<a<<", " << debugName(b)<<" = "<<b<<endl #define _overloadebug(_1, _2, _3, _4, _5, name, ...) name #define debug(...) _overloadebug(__VA_ARGS__,_deb5,_deb4,_deb3,_deb2,_deb1)(__VA_ARGS__) #define deb(...) _overloadebug(__VA_ARGS__,_deb5,_deb4,_deb3,_deb2,_deb1)(__VA_ARGS__) #define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n' //よく使うクラス、構造体 class UnionFind { public: vi par, rank, sizes; int n, trees; UnionFind(int n) : n(n), trees(n) { par.resize(n), rank.resize(n), sizes.resize(n); rep(i, n)par[i] = i, sizes[i] = 1; } int root(int x) { if (par[x] == x)return x; else return par[x] = root(par[x]); } int find(int x) { return root(x); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y)return; if (rank[x] < rank[y])swap(x, y); trees--; par[y] = x; sizes[x] += sizes[y]; if (rank[x] == rank[y])rank[x]++; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return sizes[root(x)]; } //順不同 umapなので vec<vi> sets() { vec<vi> res(trees); umap<int, vi> map; rep(i, n) map[root(i)].push_back(i); int i = 0; for (auto &&p:map) { int r = p.fi; res[i].push_back(r); for (auto &&v:p.se) { if (r == v)continue; res[i].push_back(v); } i++; } return res; } }; using bint =__int128; 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 toi128(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; } template<typename T> T minv(T a, T m); template<typename T> class Modular { public: using Type = typename decay<decltype(T::value)>::type; constexpr Modular() : value() {} template<typename U> Modular(const U &x) { value = normalize(x); } template<typename U> static Type normalize(const U &x) { Type v; if (-mod() <= x && x < mod()) v = static_cast<Type>(x); else v = static_cast<Type>(x % mod()); if (v < 0) v += mod(); return v; } const Type &operator()() const { return value; } template<typename U> explicit operator U() const { return static_cast<U>(value); } constexpr static Type mod() { return T::value; } Modular &operator+=(const Modular &other) { if ((value += other.value) >= mod()) value -= mod(); return *this; } Modular &operator-=(const Modular &other) { if ((value -= other.value) < 0) value += mod(); return *this; } template<typename U> Modular &operator+=(const U &other) { return *this += Modular(other); } template<typename U> Modular &operator-=(const U &other) { return *this -= Modular(other); } Modular &operator++() { return *this += 1; } Modular &operator--() { return *this -= 1; } Modular operator++(signed) { Modular result(*this); *this += 1; return result; } Modular operator--(signed) { Modular result(*this); *this -= 1; return result; } Modular operator-() const { return Modular(-value); } template<typename U = T> typename enable_if<is_same<typename Modular<U>::Type, signed>::value, Modular>::type &operator*=(const Modular &rhs) { #ifdef _WIN32 uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value); uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m; asm( "divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod()) ); value = m; #else value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value)); #endif return *this; } template<typename U = T> typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type &operator*=(const Modular &rhs) { int64_t q = static_cast<int64_t>(static_cast<double>(value) * rhs.value / mod()); value = normalize(value * rhs.value - q * mod()); return *this; } template<typename U = T> typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type &operator*=(const Modular &rhs) { value = normalize(value * rhs.value); return *this; } Modular &operator/=(const Modular &other) { return *this *= Modular(minv(other.value, mod())); } template<typename U> friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs); template<typename U> friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs); template<typename U> friend std::istream &operator>>(std::istream &stream, Modular<U> &number); private: Type value; }; template<typename T> bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value == rhs.value; } template<typename T, typename U> bool operator==(const Modular<T> &lhs, U rhs) { return lhs == Modular<T>(rhs); } template<typename T, typename U> bool operator==(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) == rhs; } template<typename T> bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) { return !(lhs == rhs); } template<typename T, typename U> bool operator!=(const Modular<T> &lhs, U rhs) { return !(lhs == rhs); } template<typename T, typename U> bool operator!=(U lhs, const Modular<T> &rhs) { return !(lhs == rhs); } template<typename T> bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value < rhs.value; } template<typename T> Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; } template<typename T, typename U> Modular<T> operator+(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) += rhs; } template<typename T, typename U> Modular<T> operator+(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; } template<typename T> Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; } template<typename T, typename U> Modular<T> operator-(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) -= rhs; } template<typename T, typename U> Modular<T> operator-(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; } template<typename T> Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; } template<typename T, typename U> Modular<T> operator*(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) *= rhs; } template<typename T, typename U> Modular<T> operator*(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; } template<typename T> Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; } template<typename T, typename U> Modular<T> operator/(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) /= rhs; } template<typename T, typename U> Modular<T> operator/(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; } constexpr signed MOD = 1000000007; using mint = Modular<std::integral_constant<decay<decltype(MOD)>::type, MOD>>; mint com(int n, int r) { const int NUM_ = 1400001; static ll fac[NUM_ + 1], finv[NUM_ + 1], inv[NUM_ + 1]; if (fac[0] == 0) { inv[1] = fac[0] = finv[0] = 1; for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i <= NUM_; ++i) fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD; } if (r < 0 || r > n) return 0; return mint(finv[r] * fac[n] % MOD * finv[n - r]); } mint ncr(int n, int r) { return com(n, r); } mint nhr(int n, int r) { return com(n + r - 1, r); } template<typename T> T minv(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u; } template<typename T, typename U> Modular<T> mpow(const Modular<T> &a, const U &b) { assert(b >= 0); int x = a(), res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res; } template<typename T, typename U> Modular<T> mpow(const T &a, const U &b) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res; } template<typename T> string to_string(const Modular<T> &number) { return to_string(number()); } template<typename T> std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) { return stream << number(); } template<typename T> std::istream &operator>>(std::istream &stream, Modular<T> &number) { typename common_type<typename Modular<T>::Type, int64_t>::type x; stream >> x; number.value = Modular<T>::normalize(x); return stream; } using PM = pair<mint, mint>; using vm = vector<mint>; #define _overloadvvm(_1, _2, _3, _4, name, ...) name #define vvm1(a) vec<vm> a #define vvm2(a, b) vec<vm> a(b) #define vvm3(a, b, c) vec<vm> a(b,vm(c)) #define vvm4(a, b, c, d) vec<vm> a(b,vm(c,d)) #define vvm(...) _overloadvvm(__VA_ARGS__,vvm4,vvm3,vvm2 ,vvm1)(__VA_ARGS__) vb isPrime; vi primes; void setPrime() { int len = 4010101; isPrime.resize(4010101); fill(isPrime, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i <= sqrt(len) + 5; ++i) { if (!isPrime[i])continue; for (int j = 2; i * j < len; ++j) { isPrime[i * j] = false; } } rep(i, len)if (isPrime[i])primes.pb(i); } //幾何 Pをcomplexとして扱う bool eq(double a, double b) { return fabs(a - b) < eps; } using C =complex<double>; C rot(C &a, dou th) { return a * C(cos(th), sin(th)); } dou inpro(C &a, C &b) { return real(a * conj(b)); } //90度回転させて内積が0なら平行 bool line(C a, C b, C c) { C ab = b - a; C ac = c - a; //複素数の掛け算は回転 ab *= C(0, 1); return eq(inpro(ab, ac), 0); } bool line(P a, P b, P c) { return line(C(a.fi, a.se), C(b.fi, b.se), C(c.fi, c.se)); } bool line(int xa, int ya, int xb, int yb, int xc, int yc) { C a = C(xa, ya); C b = C(xb, yb); C c = C(xc, yc); return line(a, b, c); } //便利関数 //テスト用 char ranc() { return (char) ('a' + rand() % 26); } int rand(int min, int max) { assert(min <= max); if (min >= 0 && max >= 0) { return rand() % (max + 1 - min) + min; } else if (max < 0) { return -rand(-max, -min); } else { //+ if (rand() % 2) { return rand(0, max); //- } else { return -rand(0, -min); } } } vi ranv(int n, int min, int max) { vi v(n); rep(i, n)v[i] = rand(min, max); return v; } //単調増加 vi ranvi(int n, int min, int max) { vi v(n); bool bad = 1; while (bad) { bad = 0; v.resize(n); rep(i, n) { if (i && min > max - v[i - 1]) { bad = 1; break; } if (i)v[i] = v[i - 1] + rand(min, max - v[i - 1]); else v[i] = rand(min, max); } } return v; } void ranvlr(int n, int min, int max, vi &l, vi &r) { l.resize(n); r.resize(n); rep(i, n) { l[i] = rand(min, max); r[i] = l[i] + rand(0, max - l[i]); } } //便利 汎用 //strを整数として比較 string smax(str &a, str b) { if (sz(a) < sz(b)) { return b; } else if (sz(a) > sz(b)) { return a; } else { rep(i, sz(a)) { if (a[i] < b[i]) { return b; } else if (a[i] > b[i])return a; } } return a; } //strを整数として比較 string smin(str &a, str b) { if (sz(a) < sz(b)) { return a; } else if (sz(a) > sz(b)) { return b; } else { rep(i, sz(a)) { if (a[i] < b[i]) { return a; } else if (a[i] > b[i])return b; } } return a; } template<typename V, typename T> int find(vector<V> &a, const T key) { rep(i, sz(a))if (a[i] == key)return i; return -1; } template<typename V, typename T> P find(vector<vector<V>> &a, const T key) { rep(i, sz(a)) rep(j, sz(a[0]))if (a[i][j] == key)return mp(i, j); return mp(-1, -1); } template<typename V, typename U> T find(vector<vector<vector<V>>> &a, const U key) { rep(i, sz(a))rep(j, sz(a[0]))rep(k, sz(a[0][0]))if (a[i][j][k] == key)return mt(i, j, k); return mt(-1, -1, -1); } template<typename V, typename T> int count(V &a, const T k) { return a == k; } template<typename V, typename T> int count(vector<V> &a, const T k) { int ret = 0; fora(v, a)ret += count(v, k); return ret; } template<typename V> int count_odd(V &a) { return a % 2; } template<typename V> int count_odd(vector<V> &a) { int ret = 0; fora(v, a)ret += count_odd(v); return ret; } template<typename V> int count_even(V &a) { return a % 2 == 0; } template<typename V> int count_even(vector<V> &a) { int ret = 0; fora(v, a)ret += count_even(v); return ret; } //algorythm void iota(vector<int> &ve, int s, int n) { ve.resize(n); iota(all(ve), s); } vi iota(int s, int n) { vi ve(n); iota(all(ve), s); return ve; } //便利 数学 int mod(int a, int m) { return (a % m + m) % m; } int pow(int a) { return a * a; }; ll fact(int v) { return v <= 1 ? 1 : v * fact(v - 1); } ll comi(int n, int r) { assert(n < 100); static vvi(pas, 100, 100); if (pas[0][0])return pas[n][r]; pas[0][0] = 1; rep(i, 1, 100) { pas[i][0] = 1; rep(j, 1, i + 1)pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j]; } return pas[n][r]; } void ole() { #ifdef _DEBUG debugline("ole"); exit(0); #endif string a = "a"; rep(i, 30)a += a; rep(i, 1 << 17)cout << a << endl; cout << "OLE 出力長制限超過" << endl; exit(0); } void tle() { while (inf)cout << inf << endl; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll gcd(vi b) { ll res = b[0]; for (auto &&v :b)res = gcd(v, res); return res; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll rev(ll a) { ll res = 0; while (a) { res *= 10; res += a % 10; a /= 10; } return res; } template<class T> vector<T> rev(vector<T> &a) { vector<T> ret = a; reverse(all(ret)); return ret; } ll ceil(ll a, ll b) { if (b == 0) { debugline("ceil"); deb(a, b); ole(); return -1; } else return (a + b - 1) / b; } ll sqrt(ll a) { if (a < 0) { debugline("sqrt"); deb(a); ole(); } ll res = (ll) std::sqrt(a); while (res * res < a)res++; return res; } double log(double e, double x) { return log(x) / log(e); } ll sig(ll t) { return (1 + t) * t / 2; } ll sig(ll s, ll t) { return (s + t) * (t - s + 1) / 2; } vi divisors(int v) { vi res; double lim = std::sqrt(v); for (int i = 1; i <= lim; ++i) { if (v % i == 0) { res.pb(i); if (i != v / i)res.pb(v / i); } } return res; } vi factorization(int v) { int tv = v; vi res; if (isPrime.size() == 0)setPrime(); for (auto &&p :primes) { if (v % p == 0)res.push_back(p); while (v % p == 0) { v /= p; } if (v == 1 || p * p > tv)break; } if (v > 1)res.pb(v); return res; } unordered_map<int, int> factorizationMap(int v) { int tv = v; unordered_map<int, int> res; if (isPrime.size() == 0)setPrime(); for (auto &&p :primes) { while (v % p == 0) { res[p]++; v /= p; } if (v == 1 || p * p > tv)break; } if (v > 1)res[v]++; return res; } int get(int a, int keta) { return (a / (int) pow(10, keta)) % 10; } int keta(int v) { int cou = 0; while (v) { cou++, v %= 10; } return cou; } int dsum(int v) { int ret = 0; for (; v; v /= 10)ret += v % 10; return ret; } int sumd(int v) { return dsum(v); } //変換系 template<class T, class U> vector<T> keys(vector<pair<T, U>> a) { vector<T> res; for (auto &&k :a)res.pb(k.fi); return res; } template<class T, class U> vector<U> keys(map<T, U> a) { vector<U> res; for (auto &&k :a)res.pb(k.fi); return res; } template<class T, class U> vector<U> keys(umap<T, U> a) { vector<U> res; for (auto &&k :a)res.pb(k.fi); return res; } template<class T, class U> vector<U> values(vector<pair<T, U>> a) { vector<U> res; for (auto &&k :a)res.pb(k.se); return res; } template<class T, class U> vector<T> values(map<T, U> a) { vector<T> res; for (auto &&k :a)res.pb(k.se); return res; } template<class T, class U> vector<T> values(umap<T, U> a) { vector<T> res; for (auto &&k :a)res.pb(k.se); return res; } vi list(int a) { vi res; while (a) { res.insert(res.begin(), a % 10); a /= 10; } return res; } template<class T, class U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class U> bool chmax(const U &b) { return chmax(ma, b); } template<class T, class U> bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template<class U> bool chmin(const U &b) { return chmin(mi, b); } #define chmi chmin #define chma chmax template<class T> T min(T a, signed b) { return a < b ? a : b; } template<class T> T max(T a, signed b) { return a < b ? b : a; } template<class T> T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; } template<class T> T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; } template<class T> T min(vector<T> a) { return *min_element(all(a)); } template<class T> T min(vector<T> a, int n) { return *min_element(a.begin(), a.begin() + min(n, sz(a))); } template<class T> T min(vector<T> a, int s, int n) { return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); } template<class T> T max(vector<T> a) { return *max_element(all(a)); } template<class T> T max(vector<T> a, int n) { return *max_element(a.begin(), a.begin() + min(n, sz(a))); } template<class T> T max(vector<T> a, int s, int n) { return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); } template<typename A, size_t N> A max(A (&a)[N]) { A res = a[0]; rep(i, N)res = max(res, a[i]); return res; } template<typename A, size_t N, size_t O> A max(A (&a)[N][O]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res; } template<typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res; } template<typename A, size_t N, size_t O, size_t P, size_t Q> A max(A (&a)[N][O][P][Q], const T &v) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res; } template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A max(A (&a)[N][O][P][Q][R]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res; } template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A max(A (&a)[N][O][P][Q][R][S]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res; } template<typename A, size_t N> A min(A (&a)[N]) { A res = a[0]; rep(i, N)res = min(res, a[i]); return res; } template<typename A, size_t N, size_t O> A min(A (&a)[N][O]) { A res = min(a[0]); rep(i, N)res = min(res, max(a[i])); return res; } template<typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res; } template<typename A, size_t N, size_t O, size_t P, size_t Q> A min(A (&a)[N][O][P][Q], const T &v) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res; } template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A min(A (&a)[N][O][P][Q][R]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res; } template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A min(A (&a)[N][O][P][Q][R][S]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res; } template<class T> T sum(vector<T> v, int len = -1) { if (len == -1)len = v.size(); T res = 0; chmin(len, v.size()); rep(i, len)res += v[i]; return res; } template<class T> T sum(vector<vector<T>> &v, int h = -1, int w = -1) { if (h == -1)h = v.size(); if (w == -1)w = v[0].size(); T res = 0; chmin(h, v.size()); chmin(w, v[0].size()); rep(i, h)rep(j, w)res += v[i][j]; return res; } P sump(vp &v, int len = -1) { if (len == -1)len = v.size(); P res = {0, 0}; chmin(len, v.size()); rep(i, len) { res.fi += v[i].fi; res.se += v[i].se; } return res; } ///要素が0の時、返り値は0か1か template<class T> T mul(vector<T> &v, int len = -1) { if (len == -1)len = v.size(); T res = 1; chmin(len, v.size()); rep(i, len)res *= v[i]; return res; } void clear(PQ &q) { while (q.size())q.pop(); } template<class T> void clear(queue<T> &q) { while (q.size())q.pop(); } template<class T> T *negarr(int size) { T *body = (T *) malloc((size * 2 + 1) * sizeof(T)); return body + size; } template<class T> T *negarr2(int h, int w) { double **dummy1 = new double *[2 * h + 1]; double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)]; dummy1[0] = dummy2 + w; for (int i = 1; i <= 2 * h + 1; i++) { dummy1[i] = dummy1[i - 1] + 2 * w + 1; } double **a = dummy1 + h; } //imoは0-indexed //ruiは1-indexed template<class T> vector<T> imo(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret; } template<class T> vector<T> imomi(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmin(ret[i + 1], ret[i]); return ret; } template<class T> struct ruiC { const vector<T> rui; ruiC(vector<T> &ru) : rui(ru) {} T operator()(int l, int r) { assert(l <= r); return rui[r] - rui[l]; } T operator[](int i) { return rui[i]; } }; template<class T> struct rruic { const T *rrui; rruic(T *ru) : rrui(ru) {} //n-1から-1へ T operator()(int l, int r) { assert(l >= r); return rrui[r] - rrui[l]; } T operator[](int i) { return rrui[i]; } }; template<class T> vector<T> ruiv(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i]; return ret; } template<class T> ruiC<T> ruic(vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret); } template<class T> vector<T> ruim(vector<T> &a) { vector<T> res(a.size() + 1, 1); rep(i, a.size())res[i + 1] = res[i] * a[i]; return res; } //template<class T> T *rrui(vector<T> &a) { //右から左にかけての半開区間 (-1 n-1] template<class T> rruic<T> rrui(vector<T> &a) { int len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; rer(i, len - 1)res[i - 1] = res[i] + a[i]; return rruic<T>(res); } //掛け算 template<class T> T *rruim(vector<T> &a) { int len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; res[len - 1] = 1; rer(i, len - 1)res[i - 1] = res[i] * a[i]; return res; } template<class T, class U> void inc(T &a, U v = 1) { a += v; } template<class T, class U> void inc(vector<T> &a, U v = 1) { for (auto &u :a)inc(u, v); } template<class T> void inc(vector<T> &a) { for (auto &u :a)inc(u, 1); } template<class T, class U> void plus(T &a, U v = 1) { a += v; } template<class T, class U> void plus(vector<T> &a, U v = 1) { for (auto &u :a)inc(u, v); } template<class T> void plus(vector<T> &a) { for (auto &u :a)inc(u, 1); } template<class T, class U> void dec(T &a, U v = 1) { a -= v; } template<class T, class U> void dec(vector<T> &a, U v = 1) { for (auto &u :a)dec(u, v); } template<class T> void dec(vector<T> &a) { for (auto &u :a)dec(u, 1); } template<class T, class U> void minu(T &a, U v = 1) { a -= v; } template<class T, class U> void minu(vector<T> &a, U v = 1) { for (auto &u :a)dec(u, v); } template<class T> void minu(vector<T> &a) { for (auto &u :a)dec(u, 1); } inline bool inside(int h, int w, int H, int W) { return h >= 0 && w >= 0 && h < H && w < W; } inline bool inside(int v, int l, int r) { return l <= v && v < r; } #define ins inside ll u(ll a) { return a < 0 ? 0 : a; } template<class T> vector<T> u(const vector<T> &a) { vector<T> ret = a; fora(v, ret)v = u(v); return ret; } #define MIN(a) numeric_limits<a>::min() #define MAX(a) numeric_limits<a>::max() ll goldd(ll left, ll right, function<ll(ll)> calc) { double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } ll minScore = MAX(ll); ll resIndex = left; for (ll i = left; i < right + 1; i++) { ll score = calc(i); if (minScore > score) { minScore = score; resIndex = i; } } return resIndex; } ll goldt(ll left, ll right, function<ll(ll)> calc) { double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } if (left > right) { ll l = left; left = right; right = l; } ll maxScore = MIN(ll); ll resIndex = left; for (ll i = left; i < right + 1; i++) { ll score = calc(i); if (maxScore < score) { maxScore = score; resIndex = i; } } return resIndex; } template<class T> T min(vector<vector<T>> &a) { T res = MAX(T); rep(i, a.size())chmin(res, *min_element(all(a[i]))); return res; } template<class T> T max(vector<vector<T>> &a) { T res = MIN(T); rep(i, a.size())chmax(res, *max_element(all(a[i]))); return res; } bool bget(ll m, int keta) { return (m >> keta) & 1; } int bget(ll m, int keta, int sinsuu) { m /= (ll) pow(sinsuu, keta); return m % sinsuu; } inline ll bit(int n) { return (1LL << (n)); } inline ll bit(int n, int sinsuu) { return (ll) pow(sinsuu, n); } //int bcou(ll m) { return __builtin_popcount(m & 0xFFFFFFFF) + __builtin_popcount(m >> 32); } #define bcou __builtin_popcountll //最下位ビット int lbit(int n) { return n & -n; } //最上位ビット int hbit(int n) { n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1); } //初期化は0を渡す ll nextComb(ll &mask, int n, int r) { if (!mask)return mask = (1LL << r) - 1; ll x = mask & -mask; //最下位の1 ll y = mask + x; //連続した下の1を繰り上がらせる ll res = ((mask & ~y) / x >> 1) | y; if (bget(res, n))return mask = 0; else return mask = res; } //n桁以下でビットがr個立っているもののvectorを返す vl bitCombList(int n, int r) { vl res; int m = 0; while (nextComb(m, n, r)) { res.pb(m); } return res; } //大文字小文字を区別する int altoiaZ(char c) { if ('A' <= c && c <= 'Z')return c - 'A'; return c - 'a' + 26; } char itoalaZ(int i) { if (i < 26)return 'A' + i; return 'a' + i - 26; } //aもAも0を返す 基本小文字 int altoi(char c) { if ('A' <= c && c <= 'Z')return c - 'A'; return c - 'a'; } char itoal(int i) { return 'a' + i; } int ctoi(char c) { return c - '0'; } char itoc(int i) { return i + '0'; } int vtoi(vi &v) { int res = 0; if (sz(v) > 18) { debugline("vtoi"); deb(sz(v)); ole(); } rep(i, sz(v)) { res *= 10; res += v[i]; } return res; } vi itov(int i) { vi res; while (i) { res.pb(i % 10); i /= 10; } rev(res); return res; } vector<vector<int>> ctoi(vector<vector<char>> s, char c) { int n = sz(s), m = sz(s[0]); vector<vector<int>> res(n, vector<int>(m)); rep(i, n)rep(j, m)res[i][j] = s[i][j] == c; return res; } #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); void compress(vi &a) { vi b; int len = a.size(); for (int i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); UNIQUE(b); for (int i = 0; i < len; ++i) { a[i] = lower_bound(all(b), a[i]) - b.begin(); } } void compress(int a[], int len) { vi b; for (int i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); UNIQUE(b); for (int i = 0; i < len; ++i) { a[i] = lower_bound(all(b), a[i]) - b.begin(); } } //要素が見つからなかったときに困る #define binarySearch(a, v) (binary_search(all(a),v)) #define lowerIndex(a, v) (lower_bound(all(a),v)-a.begin()) #define lowerBound(a, v) (*lower_bound(all(a),v)) #define upperIndex(a, v) (upper_bound(all(a),v)-a.begin()) #define upperBound(a, v) (*upper_bound(all(a),v)) #define ans(a) cout<<a<<endl;continue; #define poll(a) q.front();q.pop() #define dpoll(a) q.front();q.pop_front() #define pollLast(a) q.back();q.pop_back() #define pollBack(a) q.back();q.pop_back() template<class T> inline void fin(T s) { cout << s << endl, exit(0); } template<class T> struct edge { int f, t; T c; int id; int type; edge(int f, int t, T c = 1, int id = -1, int ty = -1) : f(f), t(t), c(c), id(id), type(ty) {} bool operator<(const edge &b) const { return c < b.c; } bool operator>(const edge &b) const { return c > b.c; } }; template<typename T> class graph { protected: vector<bool> _used; public : vector<vector<edge<T>>> g; vector<edge<T>> edges; int n; graph(int n) : n(n) { g.resize(n), _used.resize(n); } void clear() { g.clear(), edges.clear(); } void resize(int n) { this->n = n; g.resize(n); _used.resize(n); } int size() { return g.size(); } vector<edge<T> > &operator[](int i) { return g[i]; } virtual void add(int f, int t, T c, int id, int ty) = 0; virtual bool used(edge<T> &e) = 0; virtual bool used(int id) = 0; virtual void del(edge<T> &e) = 0; virtual void del(int id) = 0; }; template<typename T =ll> class digraph : public graph<T> { public: using graph<T>::g; using graph<T>::n; using graph<T>::edges; using graph<T>::_used; digraph(int n) : graph<T>(n) {} void add(int f, int t, T c = 1, int id = -1, int ty = -1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("digraph add"); deb(f, t, c, id, ty); ole(); } if (id == -1)id = edges.size(); g[f].emplace_back(f, t, c, id, ty); edges.emplace_back(f, t, c, id, ty); } bool used(edge<T> &e) { return _used[e.id]; } bool used(int id) { return _used[id]; } void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; } void del(int id) { _used[id] = _used[id ^ 1] = 1; } }; template<class T=int> class undigraph : public graph<T> { public: using graph<T>::g; using graph<T>::n; using graph<T>::edges; using graph<T>::_used; undigraph(int n) : graph<T>(n) { } void add(int f, int t, T c = 1, int id = -1, int ty = -1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("undigraph add"); deb(f, t, c, id, ty); ole(); } if (id == -1)id = edges.size(); g[f].emplace_back(f, t, c, id, ty); g[t].emplace_back(t, f, c, id + 1, ty); edges.emplace_back(f, t, c, id, ty); edges.emplace_back(t, f, c, id + 1, ty); } void add(edge<T> &e) { int f = e.f, t = e.t, ty = e.type; T c = e.c; add(f, t, c, ty); } bool used(edge<T> &e) { return _used[e.id]; } bool used(int id) { return _used[id]; } void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; } void del(int id) { _used[id] = _used[id ^ 1] = 1; } }; template<class T> vector<T> dijkstra(const graph<T> &g, int s, int cant_arrive = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } T initValue = MAX(T); vector<T> dis(g.n, initValue); priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.emplace(dis[to], to); } } } //基本、たどり着かないなら-1 if (cant_arrive == -1)for (auto &&d :dis) if (d == initValue)d = -1; return dis; } template<class T> vector<vector<T>> warshall(const graph<T> &g, int cant_arrive = -1) { int n = g.n; vector<vector<T> > dis(n, vector<T>(n, linf)); fora(e, g.edges) chmin(dis[e.f][e.t], e.c); rep(i, n)dis[i][i] = 0; rep(k, n)rep(i, n)rep(j, n)chmin(dis[i][j], dis[i][k] + dis[k][j]); //基本、たどり着かないなら-1 if (cant_arrive == -1)rep(i, n)rep(j, n) if (dis[i][j] == linf)dis[i][j] = -1; return dis; } template<class T=int> class tree : public undigraph<T> { public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; using undigraph<T>::_used; vi dep; vi disv; private: bool never = 1; int root = -1; vector<vector<int>> par; bool costallone; void dfs(int v, int p, int d) { dep[v] = d; par[0][v] = p; int lim = (*this)[v].size(); for (int i = 0; i < lim; i++) { int t = g[v][i].t; if (t == p)con; dfs(t, v, d + 1); } } void built() { never = 0; n = g.size(); par.assign(30, vi(n)); dep.resize(n); costallone = 1; fora(e, edges)if (e.c != 1)costallone = 0; dfs(root, -1, 0); rep(k, par.size() - 1) { rep(i, n) { if (par[k][i] == -1)par[k + 1][i] = -1; else par[k + 1][i] = par[k][par[k][i]]; } } if (costallone)disv = dep; else disv = dijkstra(*this, root); } int _lca(int u, int v) { if (dep[u] > dep[v])swap(u, v); rep(k, par.size()) { if ((dep[u] - dep[v]) >> k & 1) { v = par[k][v]; } } if (u == v)return u; rer(k, par.size() - 1) { if (par[k][u] != par[k][v]) { u = par[k][u]; v = par[k][v]; } } return par[0][u]; } int _dis(int u, int v) { int p = _lca(u, v); return disv[u] + disv[v] - disv[p] * 2; } public: tree(int n, int root = 0) : undigraph<T>(n), root(root) {} bool leaf(int v) { return sz(g[v]) == 1 && v != root; } int dis(int u, int v) { if (never) { built(); } return _dis(u, v); } int lca(int u, int v) { if (never) { built(); } return _lca(u, v); } }; //辺によりメモリを大量消費 // よってedgesを消している //頂点10^6でメモリを190MB(制限の8割)使う //軽量化のため、辺を持たないbig gridクラスがあってもいいかもしれない // template<class T=int> class grid_k6 : public undigraph<T> { public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; using undigraph<T>::_used; int H, W; int eid = 0; void add(int f, int t, T c = 1, int id = -1, int ty = -1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("grid_k6 add"); deb(f, t, c, id, ty); ole(); } g[f].emplace_back(f, t, c, eid++, ty); g[t].emplace_back(t, f, c, eid++, ty); } int getid(int h, int w) { if (!inside(h, w, H, W))return -1; return W * h + w; } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) { rep(h, H) { rep(w, W) { int f = getid(h, w); if (w + 1 < W) add(f, getid(h, w + 1)); if (h + 1 < H)add(f, getid(h + 1, w)); } } } grid_k6(_vvc ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } void add(int fh, int fw, int th, int tw) { add(getid(fh, fw), getid(th, tw)); } }; //左上から右下に移動できる template<class T=int> class digrid_k6 : public digraph<T> { public: using digraph<T>::g; using digraph<T>::n; using digraph<T>::edges; using digraph<T>::_used; int H, W; int eid = 0; void add(int f, int t, T c = 1, int id = -1, int ty = -1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("digrid_k6 add"); deb(f, t, c, id, ty); ole(); } g[f].emplace_back(f, t, c, eid++, ty); } int getid(int h, int w) { if (!inside(h, w, H, W))return -1; return W * h + w; } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W) { rep(h, H) { rep(w, W) { int f = getid(h, w); if (w + 1 < W) add(f, getid(h, w + 1)); if (h + 1 < H)add(f, getid(h + 1, w)); } } } digrid_k6(_vvc ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } void add(int fh, int fw, int th, int tw) { add(getid(fh, fw), getid(th, tw)); } }; template<class T> bool nibu(const graph<T> &g) { if (g.edges.size() == 0)return true; UnionFind uf(g.n * 2); for (auto &&e :g.edges)uf.unite(e.f, e.t + g.n), uf.unite(e.f + g.n, e.t); rep(i, g.n)if (uf.same(i, i + g.n))return 0; return 1; } //二部グラフを色分けした際の頂点数を返す template<class T> vp nibug(graph<T> &g) { vp cg; if (!nibu(g)) { debugline("nibu"); ole(); } int _n = g.size(); vb _was(_n); queue<P> q; rep(i, _n) { if (_was[i])continue; q.push(mp(i, 1)); _was[i] = 1; int red = 0; int coun = 0; while (q.size()) { int now = q.front().fi; int col = q.front().se; red += col; coun++; q.pop(); forg(gi, g[now]) { if (_was[t])continue; q.push(mp(t, col ^ 1)); _was[t] = 1; } } cg.push_back(mp(red, coun - red)); } return cg; } //機能拡張 vp vtop(vi &a, vi &b) { vp res(sz(a)); rep(i, sz(a))res[i] = mp(a[i], b[i]); return res; } void ptov(vp &p, vi &a, vi &b) { a.resize(sz(p)); b.resize(sz(p)); rep(i, sz(p))a[i] = p[i].fi, b[i] = p[i].se; } template<typename _CharT, typename _Traits, typename _Alloc> basic_string<_CharT, _Traits, _Alloc> operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) { basic_string<_CharT, _Traits, _Alloc> __str(__lhs); __str.append(to_string(__rv)); return __str; } template<typename _CharT, typename _Traits, typename _Alloc> void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) { __lhs += to_string(__rv); } template<typename _CharT, typename _Traits, typename _Alloc> basic_string<_CharT, _Traits, _Alloc> operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs, const signed __rv) { basic_string<_CharT, _Traits, _Alloc> __str(__lhs); __str.append(to_string(__rv)); return __str; } template<typename _CharT, typename _Traits, typename _Alloc> void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs, const signed __rv) { __lhs += to_string(__rv); } template<class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); } template<class T, class U> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, U v) { a.push(v); return a; } template<class T, class U> priority_queue<T> &operator+=(priority_queue<T> &a, U v) { a.push(v); return a; } template<class T, class U> set<T> &operator+=(set<T> &a, U v) { a.insert(v); return a; } template<class T, class U> set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) { a.insert(v); return a; } template<class T, class U> vector<T> &operator+=(vector<T> &a, U v) { a.pb(v); return a; } template<class T, class U> vector<T> operator+(const vector <T> &a, U v) { vector<T> ret = a; ret += v; return ret; } template<class T, class U> vector<T> operator+(U v, const vector <T> &a) { vector<T> ret = a; ret.insert(ret.begin(), v); return ret; } template<class T> vector<T> &operator+=(vector<T> &a, vector <T> &b) { fora(v, b)a += v; return a; } template<class T, class U> vector<T> &operator+=(vector<T> &a, initializer_list<U> v) { for (auto &&va :v)a.pb(va); return a; } template<class T> vector<T> &operator-=(vector<T> &a, vector <T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-="); deb(a); deb(b); ole(); } rep(i, sz(a))a[i] -= b[i]; return a; } template<class T> vector<T> operator-(vector<T> &a, vector <T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-"); deb(a); deb(b); ole(); } vector<T> res(sz(a)); rep(i, sz(a))res[i] = a[i] - b[i]; return res; } template<typename T> void remove(vector<T> &v, unsigned int i) { v.erase(v.begin() + i); } template<typename T> void remove(vector<T> &v, unsigned int s, unsigned int e) { v.erase(v.begin() + s, v.begin() + e); } template<typename T> void removen(vector<T> &v, unsigned int s, unsigned int n) { v.erase(v.begin() + s, v.begin() + s + n); } template<typename T> void erase(vector<T> &v, unsigned int i) { v.erase(v.begin() + i); } template<typename T> void erase(vector<T> &v, unsigned int s, unsigned int e) { v.erase(v.begin() + s, v.begin() + e); } template<typename T> void erasen(vector<T> &v, unsigned int s, unsigned int n) { v.erase(v.begin() + s, v.begin() + s + n); } template<typename T, typename U> void insert(vector<T> &v, unsigned int i, U t) { v.insert(v.begin() + i, t); } template<typename T, typename U> void push_front(vector<T> &v, U t) { v.insert(v.begin(), t); } template<typename T, typename U> void insert(vector<T> &v, unsigned int i, vector<T> list) { for (auto &&va :list)v.insert(v.begin() + i++, va); } template<typename T, typename U> void insert(vector<T> &v, initializer_list<U> list) { for (auto &&va :list)v.pb(va); } template<typename T, typename U> void insert(vector<T> &v, unsigned int i, initializer_list<U> list) { for (auto &&va :list)v.insert(v.begin() + i++, va); } template<typename T> void insert(set<T> &v, vector<T> list) { for (auto &&va :list)v.insert(va); } template<typename T> void insert(set<T> &v, initializer_list<T> list) { for (auto &&va :list)v.insert(va); } //閉路がなければtrue bool topo(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; queue<int> st; rep(i, n)if (nyu[i] == 0)st.push(i); while (st.size()) { int v = st.front(); st.pop(); res.pb(v); fora(e, g[v]) if (--nyu[e.t] == 0)st.push(e.t); } return res.size() == n; } //辞書順最小トポロジカルソート bool topos(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; //小さい順 priority_queue<int, vector<int>, greater<int> > q; rep(i, n)if (nyu[i] == 0)q.push(i); while (q.size()) { int i = q.top(); q.pop(); res.pb(i); fora(e, g[i])if (--nyu[e.t] == 0)q.push(e.t); } return res.size() == n; } vector<string> split(const string a, const char deli) { string b = a + deli; int l = 0, r = 0, n = b.size(); vector<string> res; rep(i, n) { if (b[i] == deli) { r = i; if (l < r)res.push_back(b.substr(l, r - l)); l = i + 1; } } return res; } vector<string> split(const string a, const string deli) { string b = a + deli; int l = 0, r = 0, n = b.size(), dn = deli.size(); vector<string> res; rep(i, n) { if (i + dn <= n && b.substr(i, i + dn) == deli) { r = i; if (l < r)res.push_back(b.substr(l, r - l)); i += dn - 1; l = i + 1; } } return res; } void yn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; } void Yn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; } void YN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; } void fyn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; exit(0); } void fYn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; exit(0); } void fYN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; exit(0); } void Possible(bool a) { if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0); } int n, m, k, d, H, W, x, y, z, q; int cou; vi a, b, c; vvi (s, 0, 0); vvc (ba, 0, 0); vp p; void solve() { din(x, pp); dou p = pp * 1.0 / 100; dou e1 = 1 / p; dou e2 = 1 / p; if (x % 2 == 1) { cout << e1 + (1 / p) * (x / 2) << endl; } else { cout << e2 + (1 / p) * ((x / 2) - 1) << endl; } } int my(int n, vi a) { return 0; } int sister(int n, vi a) { return 0; } signed main() { solve(); #define _arg n,a //cin>>n; //na(a,n); //my(_arg); //cout << my(_arg) << endl; #ifdef _DEBUG bool bad = 0; for (int i = 0, ok = 1; i < k5 && ok; i++) { int n = rand(1, 3); vi a = ranv(m, 1, 10); int myres = my(_arg); int res = sister(_arg); ok = myres == res; if (!ok) { cout << n << endl; cout << a << endl; cout << "正解 : " << res << endl; cout << "出力 : " << myres << endl; bad = 1; break; } } #endif return 0; };
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- ll X; double P; double F(int N) { return 1.0/P*N; } void solve() { int i,j,k,l,r,x,y; string s; cin>>X>>P; P/=100; if(X%2==1) { _P("%.12lf\n",1+P*F((X-1)/2)+(1-P)*F((X+1)/2)); } else { _P("%.12lf\n",F(X/2)); } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using lint = long long int; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); } template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); } int main() { cin.tie(NULL); ios::sync_with_stdio(false); int x, p; cin >> x >> p; cout << fixed << setprecision(15) << 50.0 * (x + (x & 1)) / p << '\n'; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include<bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using P = pair<ll, ll>; constexpr double PI = 3.14159265358979323846; mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count()); class ATakahashiIsMissing { public: void solve(istream& cin, ostream& cout) { SPEED; int x; cin >> x; double p; cin >> p; ll r = (x+1)/2; cout << setprecision(8) << fixed << r*100/p << endl; } }; signed main() { ATakahashiIsMissing solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; int main(){ int x;double p;cin>>x>>p;p/=100; if(x%2)printf("%.12lf\n",(x/2)*(1/p)*p+(x/2+1)*(1/p)*(1-p)+1); else printf("%.12lf\n",(x/2)*(1/p)); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.BitSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.TreeMap; public class Main implements Runnable{ static ContestScanner in;static Writer out; public static void main(String[] args) { new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); } public void run() { try { // in = new ContestScanner("in.txt"); // out = new Writer("out.txt"); in = new ContestScanner(); out = new Writer(); Main solve = new Main(); solve.solve(); in.close(); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } static void dump(int[]a){StringBuilder s=new StringBuilder();for(int i=0;i<a.length;i++) s.append(a[i]).append(" ");out.println(s.toString().trim());} static void dump(int[]a,int n){for(int i=0;i<a.length;i++)out.printf("%"+n+"d ",a[i]);out.println();} static void dump(long[]a){StringBuilder s=new StringBuilder();for(int i=0;i<a.length;i++) s.append(a[i]).append(" ");out.println(s.toString().trim());} static void dump(char[]a){for(int i=0;i<a.length;i++)out.print(a[i]);out.println();} static long pow(long a,int n){long r=1;while(n>0){if((n&1)==1)r*=a;a*=a;n>>=1;}return r;} static String itob(int a,int l){return String.format("%"+l+"s",Integer.toBinaryString(a)).replace(' ','0');} static void sort(int[]a){m_sort(a,0,a.length,new int[a.length]);} static void sort(int[]a,int l){m_sort(a,0,l,new int[l]);} static void sort(int[]a,int l,int[]buf){m_sort(a,0,l,buf);} static void sort(int[]a,int s,int l,int[]buf){m_sort(a,s,l,buf);} static void m_sort(int[]a,int s,int sz,int[]b) {if(sz<7){for(int i=s;i<s+sz;i++)for(int j=i;j>s&&a[j-1]>a[j];j--)swap(a, j, j-1);return;} m_sort(a,s,sz/2,b);m_sort(a,s+sz/2,sz-sz/2,b);int idx=s;int l=s,r=s+sz/2;final int le=s+sz/2,re=s+sz; while(l<le&&r<re){if(a[l]>a[r])b[idx++]=a[r++];else b[idx++]=a[l++];} while(r<re)b[idx++]=a[r++];while(l<le)b[idx++]=a[l++];for(int i=s;i<s+sz;i++)a[i]=b[i]; } /* qsort(3.5s)<<msort(9.5s)<<<shuffle+qsort(17s)<Arrays.sort(Integer)(20s) */ static void sort(long[]a){m_sort(a,0,a.length,new long[a.length]);} static void sort(long[]a,int l){m_sort(a,0,l,new long[l]);} static void sort(long[]a,int l,long[]buf){m_sort(a,0,l,buf);} static void sort(long[]a,int s,int l,long[]buf){m_sort(a,s,l,buf);} static void m_sort(long[]a,int s,int sz,long[]b) {if(sz<7){for(int i=s;i<s+sz;i++)for(int j=i;j>s&&a[j-1]>a[j];j--)swap(a, j, j-1);return;} m_sort(a,s,sz/2,b);m_sort(a,s+sz/2,sz-sz/2,b);int idx=s;int l=s,r=s+sz/2;final int le=s+sz/2,re=s+sz; while(l<le&&r<re){if(a[l]>a[r])b[idx++]=a[r++];else b[idx++]=a[l++];} while(r<re)b[idx++]=a[r++];while(l<le)b[idx++]=a[l++];for(int i=s;i<s+sz;i++)a[i]=b[i];} static void swap(long[] a,int i,int j){final long t=a[i];a[i]=a[j];a[j]=t;} static void swap(int[] a,int i,int j){final int t=a[i];a[i]=a[j];a[j]=t;} static int binarySearchSmallerMax(int[]a,int v)// get maximum index which a[idx]<=v {int l=-1,r=a.length-1,s=0;while(l<=r){int m=(l+r)/2;if(a[m]>v)r=m-1;else{l=m+1;s=m;}}return s;} static int binarySearchSmallerMax(int[]a,int v,int l,int r) {int s=-1;while(l<=r){int m=(l+r)/2;if(a[m]>v)r=m-1;else{l=m+1;s=m;}}return s;} @SuppressWarnings("unchecked") static List<Integer>[]createGraph(int n) {List<Integer>[]g=new List[n];for(int i=0;i<n;i++)g[i]=new ArrayList<>();return g;} void solve() throws IOException{ long x = in.nextLong(); int p = in.nextInt(); System.out.println(100.0*((x+1)/2)/p); } } @SuppressWarnings("serial") class MultiSet<T> extends HashMap<T, Integer>{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);} public MultiSet<T> merge(MultiSet<T> set) {MultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;} for(Entry<T,Integer>e:s.entrySet())l.add(e.getKey(),e.getValue());return l;} } @SuppressWarnings("serial") class OrderedMultiSet<T> extends TreeMap<T, Integer>{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);} public OrderedMultiSet<T> merge(OrderedMultiSet<T> set) {OrderedMultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;} while(!s.isEmpty()){l.add(s.firstEntry().getKey(),s.pollFirstEntry().getValue());}return l;} } class Pair implements Comparable<Pair>{ int a,b;final int hash;Pair(int a,int b){this.a=a;this.b=b;hash=(a<<16|a>>16)^b;} public boolean equals(Object obj){Pair o=(Pair)(obj);return a==o.a&&b==o.b;} public int hashCode(){return hash;} public int compareTo(Pair o){if(a!=o.a)return a<o.a?-1:1;else if(b!=o.b)return b<o.b?-1:1;return 0;} } class Timer{ long time;public void set(){time=System.currentTimeMillis();} public long stop(){return time=System.currentTimeMillis()-time;} public void print(){System.out.println("Time: "+(System.currentTimeMillis()-time)+"ms");} @Override public String toString(){return"Time: "+time+"ms";} } class Writer extends PrintWriter{ public Writer(String filename)throws IOException {super(new BufferedWriter(new FileWriter(filename)));} public Writer()throws IOException{super(System.out);} } class ContestScanner implements Closeable{ private BufferedReader in;private int c=-2; public ContestScanner()throws IOException {in=new BufferedReader(new InputStreamReader(System.in));} public ContestScanner(String filename)throws IOException {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));} public String nextToken()throws IOException { StringBuilder sb=new StringBuilder(); while((c=in.read())!=-1&&Character.isWhitespace(c)); while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();} return sb.toString(); } public String readLine()throws IOException{ StringBuilder sb=new StringBuilder();if(c==-2)c=in.read(); while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();} return sb.toString(); } public long nextLong()throws IOException,NumberFormatException {return Long.parseLong(nextToken());} public int nextInt()throws NumberFormatException,IOException {return(int)nextLong();} public double nextDouble()throws NumberFormatException,IOException {return Double.parseDouble(nextToken());} public void close() throws IOException {in.close();} }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <stdio.h> int main(void) { int x, p; scanf("%d%d", &x, &p); printf("%.12f", (double)((x + 1) / 2) * 100.0 / (double)p); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector<int> VI; typedef vector<ll> VL; typedef pair<int, int> PI; const ll mod = 1e9 + 7; double solve(ll x, double p) { return (x + 1) / 2 / p; } int main(void){ ll x; int p; cin >> x >> p; if (p == 100) { cout << (x + 1) / 2 << endl; return 0; } printf("%.15f\n", solve(x, p / 100.0)); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
// #pragma GCC target("avx2") // CPU 処理並列化 // #pragma GCC optimize("O3") // CPU 処理並列化 // #pragma GCC optimize("unroll-loops") // 条件処理の呼び出しを減らす #include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<deque> #include<stack> #include<string> #include<string.h> #include<vector> #include<set> #include<map> #include<bitset> #include<stdlib.h> #include<cassert> #include<time.h> #include<bitset> #include<numeric> using namespace std; const long long mod=1000000007; const long long inf=mod*mod; const long long d2=(mod+1)/2; const double EPS=1e-10; const double INF=1e+10; const double PI=acos(-1.0); const int C_SIZE = 3121000; long long fact[C_SIZE]; long long finv[C_SIZE]; long long inv[C_SIZE]; long long Comb(int a,int b){ if(a<b||b<0)return 0; return fact[a]*finv[b]%mod*finv[a-b]%mod; } void init_C(int n){ fact[0]=finv[0]=inv[1]=1; for(int i=2;i<n;i++){ inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod; } for(int i=1;i<n;i++){ fact[i]=fact[i-1]*i%mod; finv[i]=finv[i-1]*inv[i]%mod; } } long long pw(long long a,long long b){ if(a<0LL)return 0; if(b<0LL)return 0; long long ret=1; while(b){ if(b%2)ret=ret*a%mod; a=a*a%mod; b/=2; } return ret; } int ABS(int a){return max(a,-a);} long long ABS(long long a){return max(a,-a);} double ABS(double a){return max(a,-a);} int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; } // ここから編集しろ int main(){ int a,b;scanf("%d%d",&a,&b); double p=0.01*b; double ret=0; if(a%2){ ret=p*(1+(a-1)/2/p)+(1-p)*(1+(a+1)/2/p); }else{ ret=a/2/p; } printf("%.12f\n",ret); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
/* ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░▌ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌ ▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▄ ▐░▌ ▐░▌ ▄▄▄▄▄▄▄▄ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░░░░░░░░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌░▌ ▐░▌ ▐░▌ ▀▀▀▀▀▀█░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░▌░▌ ▐░▐░▌ ▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░▌ ▐░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░▌ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ */ //#pragma optimization_level 3 //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <bitset> #include <chrono> #include <ctime> #include <queue> #include <math.h> #include <deque> #include <stack> #include <iomanip> #include <assert.h> #include <stdio.h> #include <cstring> #include <random> using namespace std; //#define int long long #define ll long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define pld pair<ld, ld> #define ti tuple<int, int, int> #define vi vector <int> #define vpi vector <pii> #define vld vector <ld> #define try tr #define left left11 #define right right11 #define lb lower_bound #define ub upper_bound #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() #define pb push_back #define pf push_front #define sqr(a) ((a) * (a)) #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define x first #define y second mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); clock_t START; inline ld TIME() { return (ld) (clock() - START) / CLOCKS_PER_SEC; } void SHOW() { cout << fixed << setprecision(10); cout << TIME() << " SECONDS FROM START\n"; } ld TL = 2.0; int calls = 0; inline bool IS() { if(++calls == 1000) { calls = 0; if(TL - TIME() < 0.1) return true; } return false; } template<typename T1, typename T2> inline bool amin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; } template<typename T1, typename T2> inline bool amax(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << p.first << ' ' << p.second; return os; } template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &u : v) is >> u; return is; } template<typename T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto &u : v) os << u << ' '; return os; } int hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937}, mod = hash_mod[rnd() % 4]; int hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4]; int binpow(int x, int p) { int res = 1; while(p) { if(p % 2) res = (res * x) % mod; x = (x * x) % mod; p /= 2; } return res; } const int N = 5e5 + 7, NS = 2e3 + 7, lg = 20, sq = 550, inf = 2e9 + 7, SM = 1e2 + 7; const ld eps = 1e-9; void solve() { ld x, p; cin >> x >> p; p /= 100; if((int) (x) % 2 == 0) cout << fixed << setprecision(10) << x / (2 * p); else { cout << fixed << setprecision(10) << 1 + p * (x - 1) / (2 * p) + (1 - p) * (x + 1) / (2 * p); } } signed main() { fast solve(); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <fstream> #include <cassert> #include <typeinfo> #include <vector> #include <stack> #include <cmath> #include <set> #include <map> #include <string> #include <algorithm> #include <cstdio> #include <queue> #include <iomanip> #include <cctype> #include <random> #include <complex> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<P,int> pip; typedef vector<pip> vip; const int inf=1<<29; const ll INF=1ll<<58; const double pi=acos(-1); const double eps=1e-7; const ll mod=1e9+7; const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0}; int x; double p; int main(){ cin>>x>>p; p/=100; if(x%2==1) x++; cout<<syosu(9)<<(double)x/2/p<<endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; #define rep(i, N) for (int i = 0; i < N; i++) ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; double solve(int x, double P) { return (double)x / 2 / P; } int main() { int x, p; cin >> x >> p; double P = p / 100.0; double ans; if (x % 2 == 0) ans = solve(x, P); else ans = 1 + P * solve(x - 1, P) + (1 - P) * solve(x + 1, P); printf("%.15f\n", ans); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20); #endif int x; int per; cin >> x >> per; double p = per/100.0; if (x % 2 == 0) { cout << (1/p) * (x/2) << endl; } else { double l = (1/p) * ((x - 1)/2) + 1; double r = (1/p) * ((x + 1)/2) + 1; cout << (per * l + (100 - per) * r) / 100.0 << endl; } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #define MOD 1000000007 typedef long long ll; using namespace std; double calc(int x,int p){ return x*100.0/p; } int main(){ int x,p; cin>>x>>p; double ans=0.0; if(x%2==0) ans=calc(x/2,p); else{ ans=calc((x-1)/2,p)*p/100+calc((x+1)/2,p)*(100-p)/100+1; } cout<<fixed<<setprecision(10)<<ans<<endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef complex<double> point; #define mapii map<int, int> #define debug(a) cout << #a << ": " << a << endl #define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl #define fdto(i, r, l) for(int i = (r); i >= (l); --i) #define fto(i, l, r) for(int i = (l); i <= (r); ++i) #define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++) #define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++) #define ii pair<int, int> #define iii pair<int, ii> #define ff first #define ss second #define mp make_pair #define pb push_back #define maxN 100005 #define MOD 1000 #define oo 1000000000000000007LL #define sz(a) (int)a.size() const double PI = acos(-1.0); double fRand(double fMin, double fMax) { double f = (double)rand() / RAND_MAX; return fMin + f * (fMax - fMin); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } int x, p; int main () { scanf("%d%d", &x, &p); double ans = (x+1)/2 * 100.0/p; printf("%.9g", ans); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long lli; typedef double lld; typedef vector<lli> vll; typedef vector<bool> vbl; typedef vector<double> vdl; typedef vector<vector<lli>> mat; typedef vector<vdl> mad; typedef unordered_map<lli,unordered_map<lli,lli>> graph; typedef complex<double> cmp; typedef vector<cmp> vcl; lli x,p; int main(){ cin >> x >> p; cout << setprecision(17); if(x%2 == 0) cout << 100.0/p*(x/2)<< endl; else cout << 100.0/p*((x+1)/2)*(100-p)/100+100.0/p*((x-1)/2)*p/100+1 << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,b) rng(i,0,b) #define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;} template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;} template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; using pi=pair<int,int>; using vi=vc<int>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.a<<","<<p.b<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } #define mp make_pair #define mt make_tuple #define one(x) memset(x,-1,sizeof(x)) #define zero(x) memset(x,0,sizeof(x)) #ifdef LOCAL void dmpr(ostream&os){os<<endl;} template<class T,class... Args> void dmpr(ostream&os,const T&t,const Args&... args){ os<<t<<" "; dmpr(os,args...); } #define dmp2(...) dmpr(cerr,"Line:",__LINE__,##__VA_ARGS__) #else #define dmp2(...) void(0) #endif using uint=unsigned; using ull=unsigned long long; template<class t,size_t n> ostream& operator<<(ostream&os,const array<t,n>&a){ return os<<vc<t>(all(a)); } template<int i,class T> void print_tuple(ostream&,const T&){ } template<int i,class T,class H,class ...Args> void print_tuple(ostream&os,const T&t){ if(i)os<<","; os<<get<i>(t); print_tuple<i+1,T,Args...>(os,t); } template<class ...Args> ostream& operator<<(ostream&os,const tuple<Args...>&t){ os<<"{"; print_tuple<0,tuple<Args...>,Args...>(os,t); return os<<"}"; } void print(ll x,int suc=1){ cout<<x; if(suc==1) cout<<"\n"; if(suc==2) cout<<" "; } ll read(){ ll i; cin>>i; return i; } vi readvi(int n,int off=0){ vi v(n); rep(i,n)v[i]=read()+off; return v; } template<class T> void print(const vector<T>&v,int suc=1){ rep(i,v.size()) print(v[i],i==int(v.size())-1?suc:2); } string readString(){ string s; cin>>s; return s; } template<class T> T sq(const T& t){ return t*t; } //#define CAPITAL void yes(bool ex=true){ #ifdef CAPITAL cout<<"YES"<<endl; #else cout<<"Yes"<<endl; #endif if(ex)exit(0); } void no(bool ex=true){ #ifdef CAPITAL cout<<"NO"<<endl; #else cout<<"No"<<endl; #endif if(ex)exit(0); } void possible(bool ex=true){ #ifdef CAPITAL cout<<"POSSIBLE"<<endl; #else cout<<"Possible"<<endl; #endif if(ex)exit(0); } void impossible(bool ex=true){ #ifdef CAPITAL cout<<"IMPOSSIBLE"<<endl; #else cout<<"Impossible"<<endl; #endif if(ex)exit(0); } constexpr ll ten(int n){ return n==0?1:ten(n-1)*10; } const ll infLL=LLONG_MAX/3; #ifdef int const int inf=infLL; #else const int inf=INT_MAX/2-100; #endif int topbit(signed t){ return t==0?-1:31-__builtin_clz(t); } int topbit(ll t){ return t==0?-1:63-__builtin_clzll(t); } int botbit(signed a){ return a==0?32:__builtin_ctz(a); } int botbit(ll a){ return a==0?64:__builtin_ctzll(a); } int popcount(signed t){ return __builtin_popcount(t); } int popcount(ll t){ return __builtin_popcountll(t); } bool ispow2(int i){ return i&&(i&-i)==i; } int mask(int i){ return (int(1)<<i)-1; } bool inc(int a,int b,int c){ return a<=b&&b<=c; } template<class t> void mkuni(vc<t>&v){ sort(all(v)); v.erase(unique(all(v)),v.ed); } ll rand_int(ll l, ll r) { //[l, r] #ifdef LOCAL static mt19937_64 gen; #else static random_device rd; static mt19937_64 gen(rd()); #endif return uniform_int_distribution<ll>(l, r)(gen); } template<class t> int lwb(const vc<t>&v,const t&a){ return lower_bound(all(v),a)-v.bg; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int x;cin>>x; using ld=long double; ld p;cin>>p; p/=100; ld ans=0; if(x%2==0){ ans=x/2/p; }else{ ans=1; ans+=(x-1)/2/p*p; ans+=(x+1)/2/p*(1-p); } cout<<ans<<endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.*; import java.math.BigDecimal; import java.util.Arrays; import java.util.StringJoiner; import java.util.StringTokenizer; import java.util.function.Function; public class Main { static int X, P; public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); X = sc.nextInt(); P = sc.nextInt(); System.out.println(BigDecimal.valueOf(solve()).toPlainString()); } static double solve() { if( X % 2 == 1 ) { double p = (double)P/100; return 1 + f(X-1) * p + f(X+1) * (1-p); } else { return f(X); } } // xは偶数 static double f(int x) { // f(x) = 1 + p*f(x-2) + q*f(x) // => f(x) = f(x-2) + 1/p // => f(x) = 1/p * 1/2 * x double p = (double)P/100; return (double)x / 2 / p; } @SuppressWarnings("unused") static class FastScanner { private BufferedReader reader; private StringTokenizer tokenizer; FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } long nextLong() { return Long.parseLong(next()); } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArray(int n, int delta) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt() + delta; return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } static <A> void writeLines(A[] as, Function<A, String> f) { PrintWriter pw = new PrintWriter(System.out); for (A a : as) { pw.println(f.apply(a)); } pw.flush(); } static void writeLines(int[] as) { PrintWriter pw = new PrintWriter(System.out); for (int a : as) pw.println(a); pw.flush(); } static void writeLines(long[] as) { PrintWriter pw = new PrintWriter(System.out); for (long a : as) pw.println(a); pw.flush(); } static int max(int... as) { int max = Integer.MIN_VALUE; for (int a : as) max = Math.max(a, max); return max; } static int min(int... as) { int min = Integer.MAX_VALUE; for (int a : as) min = Math.min(a, min); return min; } static void debug(Object... args) { StringJoiner j = new StringJoiner(" "); for (Object arg : args) { if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg)); else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg)); else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg)); else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg)); else j.add(arg.toString()); } System.err.println(j.toString()); } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; //typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 int X, P, Q; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> X >> P; Q = 100-P; double np = 1+(double)Q/(double)P; double ans = 0; if (X%2) { ans += (P/100.0)*(1+((X-1)/2)*np); ans += (1-(P/100.0))*(1+((X+1)/2)*np); } else { ans += (X/2)*np; } cout << fixed << setprecision(20) << ans << "\n"; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
python3
print((int(input())+1)//2/int(input())*100)
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include "iostream" #include "iomanip" using namespace std; long double X; long double rad; long double ans; int main() { cin >> X >> rad; if ((long long int)X % 2 == 0) { for (int i = 0; i < 10000000; i++) { ans = (ans + X - rad / 100 * ans + (100.0 - rad) / 100 * ans) / 2; } } else { for (int i = 0; i < 10000000; i++) { ans = (ans+1 + X - rad / 100 * ans + (100.0 - rad) / 100 * ans) / 2; } } cout << setprecision(15) << ans<<"\n"; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using ll = long long; int main() { ll x, p; std::cin >> x >> p; if (x == 0) { return std::cout << 0 << std::endl, 0; } std::cout << std::fixed << std::setprecision(15) << (x % 2 == 0 ? 50.0 * x / p : 50.0 * (1 + x) / p) << std::endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <deque> #include <queue> #include <array> #include <set> #include <map> #include <cmath> #include <algorithm> #include <numeric> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cstdint> #include <cassert> #include <random> using namespace std; using i64 = int64_t; using i32 = int32_t; template<class T, class U> void init_n(vector<T>& v, size_t n, U x) { v = vector<T>(n, x); } template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); } template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) { v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; } template<class T> void read_n(T a[], size_t n, size_t o = 0) { for (size_t i=o; i<n+o; ++i) cin >> a[i]; } template<class T> T gabs(const T& x) { return max(x, -x); } #define abs gabs int main() { i64 x; double p; cin >> x >> p; p /= 100; double ans; if (x % 2 == 0) { ans = x / (2 * p); } else { ans = 1.0 + (p * (x - 1) + (1.0 - p) * (x + 1)) / (2 * p); } printf("%.10f\n", ans); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <iomanip> #pragma GCC optimize("Ofast") //#pragma GCC optimization("unroll-loops, no-stack-protector") //#pragma GCC target("avx,avx2,fma") using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template<typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define endl '\n'; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; } template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); } #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr); #else #define eprintf(...) 42 #endif clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } const ll INF = (ll)1e18; ll MOD; ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mul(ll x, ll y) { return (x * y) % MOD; } ll bin_pow(ll x, ll p) { if (p == 0) return 1; if (p & 1) return mul(x, bin_pow(x, p - 1)); return bin_pow(mul(x, x), p / 2); } const int N = 2000100; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ld p, ans = 0; ll x; cin >> x >> p; p /= 100; if (x % 2 == 0) { ans = x / 2 / p; } else { ans = 1 + (x + 1) * (1 - p) / 2 / p + (x - 1) / 2; } cout << setprecision(10) << ans << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
// need #include <iostream> #include <algorithm> // data structure #include <bitset> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #include <complex> //#include <deque> #include <valarray> // stream //#include <istream> //#include <sstream> //#include <ostream> #include <fstream> // etc #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <chrono> #include <random> #include <numeric> // input #define INIT std::ios::sync_with_stdio(false);std::cin.tie(0); #define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int i=0; i<n; ++i){MACRO_VEC_ROW_Scan(i, __VA_ARGS__);} template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); } template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { std::cin >> t[p]; } template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i; #define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& r:c)for(auto& i:r)std::cin>>i; // output #define OUT(d) std::cout<<(d); #define FOUT(n, d) std::cout<<std::fixed<<std::setprecision(n)<<(d); #define SOUT(n, c, d) std::cout<<std::setw(n)<<std::setfill(c)<<(d); #define SP std::cout<<" "; #define TAB std::cout<<"\t"; #define BR std::cout<<"\n"; #define SPBR(i, n) std::cout<<(i + 1 == n ? '\n' : ' '); #define ENDL std::cout<<std::endl; #define FLUSH std::cout<<std::flush; #define SHOW(d) {std::cerr << #d << "\t:" << (d) << "\n";} #define SHOWVECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} #define SHOWVECTOR2(v) {std::cerr << #v << "\t:\n";for(const auto& xxx : v){for(const auto& yyy : xxx){std::cerr << yyy << " ";}std::cerr << "\n";}} #define SHOWQUEUE(a) {auto tmp(a);std::cerr << #a << "\t:";while(!tmp.empty()){std::cerr << tmp.front() << " ";tmp.pop();}std::cerr << "\n";} // utility #define ALL(a) (a).begin(),(a).end() #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i) #define REP(i, n) for(int i=0;i<int(n);++i) #define RREP(i, n) for(int i=int(n)-1;i>=0;--i) #define FORLL(i, a, b) for(ll i=ll(a);i<ll(b);++i) #define RFORLL(i, a, b) for(ll i=ll(b)-1;i>=ll(a);--i) #define REPLL(i, n) for(ll i=0;i<ll(n);++i) #define RREPLL(i, n) for(ll i=ll(n)-1;i>=0;--i) #define IN(a, x, b) (a<=x && x<b) template<typename T> inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; } template<typename T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; } #define EXCEPTION(msg) throw std::string("Exception : " msg " [ in ") + __func__ + " : " + std::to_string(__LINE__) + " lines ]" #define TRY(cond, msg) try {if (cond) EXCEPTION(msg);}catch (std::string s) {std::cerr << s << std::endl;} void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n"; } // test template<class T> std::vector<std::vector<T>> VV(int n, int m, T init = T()) { return std::vector<std::vector<T>>(n, std::vector<T>(m, init)); } template<typename S, typename T> std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; using PAIR = std::pair<int, int>; using PAIRLL = std::pair<ll, ll>; constexpr int INFINT = 1 << 30; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double EPS = 1e-9; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template<class T, size_t N> void FILL(T(&a)[N], const T& val) { for (auto& x : a) x = val; } template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T& val) { for (auto& b : a) FILL(b, val); } template<class T> void FILL(std::vector<T>& a, const T& val) { for (auto& x : a) x = val; } template<class ARY, class T> void FILL(std::vector<std::vector<ARY>>& a, const T& val) { for (auto& b : a) FILL(b, val); } // ------------>8------------------------------------->8------------ signed main() { INIT; VAR(int, x, p); FOUT(12, (x + 1) / 2 * 100. / p)BR; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i,n) rep2(i,0,n) #define rep2(i,m,n) for(int i=m;i<(n);i++) #define ALL(c) (c).begin(),(c).end() int x, pp; bool f; int main() { cin >> x >> pp; double p = (double)pp / 100; f = x & 1; int zan = x / 2; double ret; if (f) { ret = (1/p) * (p * zan + (1-p) * (zan + 1)) + 1; } else { ret = (1/p) * zan; } printf("%.8f\n", ret); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using cd = complex<ld>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int x, p; cin >> x >> p; cout.precision(10); x += x % 2; cout << fixed << x * 100.0 / (2 * p); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
// includes #include <bits/stdc++.h> using namespace std; // macros #define pb emplace_back #define mk make_pair #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr) #define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define bit(n) (1LL<<(n)) // functions template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;} template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;} template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;} template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} // types using ll = long long int; using P = pair<int, int>; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1000000007; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; // io struct fast_io{ fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);} } fast_io_; int main(int argc, char const* argv[]) { ll x; double p; cin >> x >> p; p *= 0.01; double res = (x / 2) / p; if(x & 1)res += 1 / p; cout << res << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
python3
x = int(input()) p = int(input()) / 100 print(((x + 1) // 2) / p)
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl #define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl #define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl #define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl #define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl #define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl using namespace std; typedef pair<int,int> P; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<P> vp; typedef vector<string> vs; const int MAX_N = 100005; int main() { cin.tie(0); ios::sync_with_stdio(false); int x, p; cin >> x >> p; if(p == 100){ printf("%.12lf\n",(double)((x+1)/2)); return 0; } printf("%.12lf\n",100.0*((x+1)/2)/p); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define ll long long #define se second #define fi first #define mp make_pair #define pb push_back #define all(_v) _v.begin(), _v.end() const int mod = (int)1e9 + 7; const int INF = (int)1e9; const ll LINF = (ll)1e18; const int N = (int)1e5 + 100; const int MAXA = (int)3e6; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //ifstream cin("input.txt"); //ofstream cout("output.txt"); long double x,p; cin >> x >> p; p /= 100; cout << fixed << setprecision(7); if(!(int(x) & 1))cout << x / (2 * p); else cout << (x + 1) / (2 * p); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <functional> typedef long long ll; using namespace std; #ifndef LOCAL #define debug(...) ; #else #define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl; template<typename T> ostream &operator<<(ostream &out, const vector<T> &v); template<typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template<typename T> ostream &operator<<(ostream &out, const vector<T> &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } void _tostr_rec(ostringstream &oss) { oss << "\b\b \b"; } template<typename Head, typename... Tail> void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << head << ", "; _tostr_rec(oss, forward<Tail>(tail)...); } template<typename... T> string _tostr(T &&... args) { ostringstream oss; int size = sizeof...(args); if (size > 1) oss << "{"; _tostr_rec(oss, forward<T>(args)...); if (size > 1) oss << "}"; return oss.str(); } #endif #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 200010 double calc(int X, int P) { debug(X, X / 2 * 100.0 / P); X /= 2; return X * 100.0 / P; } int main() { int X, P; cin >> X >> P; double ans = 0; if (X % 2) { ans = (calc(X - 1, P) * P + calc(X + 1, P) * (100 - P)) / 100.0 + 1; } else { ans = calc(X, P); } printf("%.10lf\n", ans); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll; template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; } template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; } int main() { int x; int p; while(~scanf("%d%d", &x, &p)) { double t = p * 1e-2; double ans = (x / 2) * (1. / t); if(x % 2 != 0) ans = 1 + t * ans + (ans + (1 / t)) * (1 - t); printf("%.10f\n", ans); } return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main implements Runnable { public static void main(String[] args) { new Main().run(); } public void run() { Scanner sc = new Scanner(System.in); long x = sc.nextLong(); double p = sc.nextDouble(); p /= 100; if (x % 2 == 1) { ++x; } x /= 2; System.out.println(x / p); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
python3
x = int(input()) p = int(input()) if x % 2 == 0: print (100 * (x//2) / p) else: print ((100 * (x//2+1) / p))
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<string> #include<vector> #include<map> #include<algorithm> #include<cmath> #include<set> #include<iomanip> using namespace std; double memo[2000]={}; int main(){ int p; int64_t x; cin>>x>>p; double res=0.0; if(p==100){ int64_t res=0; if(x%2==1){ res=x/2+1; }else{ res=x/2; } cout<<res<<endl; }else{ if(x%2==1){ x=(x+1)/2; res=100.0*x/(1.0*p); }else{ x=x/2; res=100.0*x/(1.0*p); } cout<<setprecision(13)<<res<<endl; } return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint mod = 1e9 + 7; #define all(x) (x).begin(), (x).end() #define bitcount(n) __builtin_popcountl((lint)(n)) #define fcout cout << fixed << setprecision(15) #define highest(x) (63 - __builtin_clzl(x)) #define rep(i, n) for(int i = 0; i < n; i++) const int inf9 = 1e9; const lint inf18 = 1e18; template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; } lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }} struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); } template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; } template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; } template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } } template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; } struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint P(int n, int r){ if(r < 0 || n < r) return 0; return (fact[n] * inv[n - r] % mod); } lint C(int p, int q){ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } }; template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; } template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; } double solve(lint dist, double p){ return dist / p; } int main(){ lint x; int p_100; cin >> x >> p_100; double p = p_100 / 100.0; if(x % 2){ fcout << 1 + p * solve(x / 2, p) + (1 - p) * solve(x / 2 + 1, p) << endl; }else{ fcout << solve(x / 2, p) << endl; } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using uint=unsigned int; using pcc=pair<char,char>; using pii=pair<int,int>; using pll=pair<ll,ll>; using pdd=pair<double,double>; using tuplis=pair<ll,pll>; template<class T> using pq=priority_queue<T,vector<T>,greater<T>>; const ll LINF=0x1fffffffffffffff; const ll MOD=1000000007; const ll MODD=0x3b800001; const int INF=0x3fffffff; const double DINF=numeric_limits<double>::infinity(); const vector<pii> four={{-1,0},{0,1},{1,0},{0,-1}}; #define _overload4(_1,_2,_3,_4,name,...) name #define _overload3(_1,_2,_3,name,...) name #define _rep1(n) _rep2(i,n) #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(ll i=a;i<b;++i) #define _rep4(i,a,b,c) for(ll i=a;i<b;i+=c) #define rep(...) _overload4(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__) #define _rrep1(n) _rrep2(i,n) #define _rrep2(i,n) _rrep3(i,0,n) #define _rrep3(i,a,b) for(ll i=b-1;i>=a;i--) #define _rrep4(i,a,b,c) for(ll i=a+(b-a-1)/c*c;i>=a;i-=c) #define rrep(...) _overload4(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__) #define each(i,a) for(auto&& i:a) #define sum(...) accumulate(range(__VA_ARGS__),0LL) #define dsum(...) accumulate(range(__VA_ARGS__),double(0)) #define _range(i) (i).begin(),(i).end() #define _range2(i,k) (i).begin(),(i).begin()+k #define _range3(i,a,b) (i).begin()+a,(i).begin()+b #define range(...) _overload3(__VA_ARGS__,_range3,_range2,_range)(__VA_ARGS__) #define _rrange(i) (i).rbegin(),(i).rend() #define _rrange2(i,k) (i).rbegin(),(i).rbegin()+k #define _rrange3(i,a,b) (i).rbegin()+a,(i).rbegin()+b #define rrange(...) _overload3(__VA_ARGS__,_rrange3,_rrange2,_rrange)(__VA_ARGS__) #define yes(i) out(i?"yes":"no") #define Yes(i) out(i?"Yes":"No") #define YES(i) out(i?"YES":"NO") #define Possible(i) out(i?"Possible":"Impossible") #define elif else if #define unless(a) if(!(a)) #define mp make_pair #define mt make_tuple #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define STR(...) string __VA_ARGS__;in(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;in(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;in(__VA_ARGS__) #define vec(type,name,...) vector<type> name(__VA_ARGS__) #define VEC(type,name,size) vector<type> name(size);in(name) #define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name) #define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) __attribute__((constructor)) void SETTINGS(){cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);}; template<class T> inline constexpr T gcd (T a,T b) {if(!a||!b)return 0;return a%b?gcd(b,a%b):b;} template<class T> inline constexpr T lcm (T a,T b) {return a*b/gcd(a,b);} template<class T> inline constexpr T min(vector<T>& v){return *min_element(range(v));} inline char min(string& v){return *min_element(range(v));} template<class T> inline constexpr T max(vector<T>& v){return *max_element(range(v));} inline char max(string& v){return *max_element(range(v));} inline ll pow(ll a,ll b){if(b==0)return 1;ll ans=pow(a,b/2);return ans*ans*(b&1?a:1);} inline ll modpow(ll a,ll b,ll mod){if(b==0)return 1;ll ans=pow(a,b/2);return ans*ans*(b&1?a:1)%mod;} template<typename T> inline bool update_min(T& mn,const T& cnt){if(mn>cnt){mn=cnt;return 1;}else return 0;} template<typename T> inline bool update_max(T& mx,const T& cnt){if(mx<cnt){mx=cnt;return 1;}else return 0;} inline void in() {} template<class T> istream& operator >> (istream& is, vector<T>& vec); template<class T,size_t size> istream& operator >> (istream& is, array<T,size>& vec); template<class T,class L> istream& operator >> (istream& is, pair<T,L>& p); template<class T> ostream& operator << (ostream& os, vector<T>& vec); template<class T,class L> ostream& operator << (ostream& os, pair<T,L>& p); template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;} template<class T,class L> istream& operator >> (istream& is, pair<T,L>& p){is >> p.first;is >> p.second;return is;} template<class T> ostream& operator << (ostream& os, vector<T>& vec){os << vec[0];rep(i,1,vec.size()){os << ' ' << vec[i];}return os;} template<class T> ostream& operator << (ostream& os, deque<T>& deq){os << deq[0];rep(i,1,deq.size()){os << ' ' << deq[i];}return os;} template<class T,class L> ostream& operator << (ostream& os, pair<T,L>& p){os << p.first << " " << p.second;return os;} template<class T,class L> pair<T,L> operator + (pair<T,L> a, pair<T,L> b){return {a.first + b.first, a.second + b.second};} template<class T,class L> pair<T,L> operator +=(pair<T,L> a, pair<T,L> b){a.first += b.first; a.second += b.second; return a;} template <class Head, class... Tail> inline void in(Head&& head,Tail&&... tail){cin>>head;in(move(tail)...);} template <class T> inline bool out(T t){cout<<t<<'\n';return 0;} inline bool out(){cout<<'\n';return 0;} template <class Head, class... Tail> inline bool out(Head head,Tail... tail){cout<<head<<' ';out(move(tail)...);return 0;} template <class T> inline void err(T t){cerr<<t<<'\n';} inline void err(){cerr<<'\n';} template <class Head, class... Tail> inline void err(Head head,Tail... tail){cerr<<head<<' ';out(move(tail)...);} signed main(){ LL(x,p1); double p=p1/100.0; if(x&1){ out((x+1)/2/p); }else{ out(x/2/p); } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
// g++ -std=c++11 a.cpp #include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<unordered_map> #include<utility> #include<cmath> #include<random> #include<cstring> #include<queue> #include<stack> #include<bitset> #include<cstdio> #include<sstream> #include<iomanip> #include<assert.h> #include<typeinfo> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define FOR(i,a) for(auto i:a) #define pb push_back #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) #define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");} #define show2d(v) {rep(__,v.size())show1d(v[__]);} using namespace std; //kaewasuretyuui typedef long long ll; #define int ll typedef int Def; typedef pair<Def,Def> pii; typedef vector<Def> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef vector<string> vs; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<Def,pii> pip; typedef vector<pip>vip; #define mt make_tuple typedef tuple<int,int,int,int> tp; typedef vector<tp> vt; template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;} template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;} //template<class C>constexpr int size(const C &c){return (int)c.size();} //template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;} const double PI=acos(-1); const double EPS=1e-9; Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10; // int dx[]={0,1,0,-1}; // int dy[]={1,0,-1,0};//RDLU #define yes puts("YES") #define no puts("NO") signed main(){ ios::sync_with_stdio(false); cin.tie(0); int x,p; cin>>x>>p; cout<<shosu(9)<<(x+1)/2*100./p<<endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iomanip> #include <iostream> using namespace std; int main () { int n, p; cin >> n >> p; cout << setprecision(12) << (n%2 ? 100.0 / p * (n/2 + 1) : 100.0 / p * (n/2)) << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; const int inf = numeric_limits<int>::max() / 2; int main(void){ int x,p; cin >> x >> p; cout << setprecision(15) << ceil(x/2.0) * (100.0/p) << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll x,p;cin>>x>>p; if(p==100){ if(x%2) cout<<1+(x-1)/2<<endl; else cout<<x/2<<endl; } else{ bool f=false; if(x%2){ x++; f=true; } ld a= x/2*(100.0/p), b=(x-2)/2*(100.0/p); if(!f){ cout<<fixed<<setprecision(10)<<a<<endl; } else{ ld res=a*(100.0-p)/100 + b*p/100.0; cout<<fixed<<setprecision(10)<<1+res<<endl; } } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
python3
x = int(input()) p = int(input()) l = p / 100 def f(d): return (d / 2) * 100 / p if x % 2 == 0: res = f(x) else: res = 1 + l * f(x - 1) + (1 - l) * f(x + 1) print(res)
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> using namespace std; int main(){ cout.precision(20); long long x; long double p,ans; cin >> x >> p; ans = (x/2)*100/p; if(x%2){ ans += 100/p; } cout << ans << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int x, percent; double p; cin >> x >> percent; p = percent / 100.0; double e = ((x + 1) / 2) / p; cout << setprecision(6) << fixed << e << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <map> #include <algorithm> #include <string> #include <utility> #include <set> #include <stack> #include <deque> #include <ctime> #include <random> #include <cassert> #include <cmath> #include <climits> #include <queue> #include <cstring> #include <bitset> #include <iomanip> #include <chrono> /* #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("popcnt") #pragma GCC target("avx2") */ #ifdef LOCAL #define dbg(x) cout << #x << " : " << x << endl; #else #define dbg(x) #endif #define int long long #define pb push_back #define ppb pop_back() #define mp make_pair #define fi(a,b) for (int i=a;i<b;i++) #define fj(a,b) for (int j=a;j<b;j++) #define fk(a,b) for (int k=a;k<b;k++) #define fi1(a,b) for (int i=a-1;i>=b;i--) #define fj1(a,b) for (int j=a-1;j>=b;j--) #define fk1(a,b) for (int k=a-1;k>=b;k--) #define fx(x,a) for (auto& x : a) #define rep(i, a, b) for (int i = a; i < b; ++i) #define rep1(i, a, b) for (int i = a - 1; i >= b; --i) #define siz(x) (int)x.size() #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; } template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; } ostream& operator << (ostream &a, const vector<int> &b) { for (auto k : b) cout << k << ' '; return a; } typedef long long ll; typedef unsigned long long ull; typedef char ch; typedef string str; typedef pair<int, int> pii; typedef map<int, int> mii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef vector<vpii> vvpii; typedef vector<ch> vch; typedef vector<vch> vvch; typedef vector<str> vs; const int MOD = 1000000007; const int INF = 1000000050; const long long BIG = (long long)2e18 + 50; const int MX = 200010; const double EPS = 1e-9; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); double p; double M(int x) { return x / (2 * p); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int x; cin >> x >> p; p /= 100; double ans; if (x % 2) ans = M(x - 1) * p + M(x + 1) * (1 - p) + 1; else ans = M(x); cout << setprecision(15) << fixed; cout << ans << '\n'; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int main() { int x; double p; cin >> x >> p; p /= 100; double res = 0; if(x & 1) { res = 1 + (x - 1.0) / 2 + (1 - p) * (x + 1.0) / 2 / p; } else { res = x / 2.0 / p; } cout << fixed << setprecision(10) << res << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef pair<LL, LL> PLL; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(),(c).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define FF first #define SS second template<class S, class T> istream& operator>>(istream& is, pair<S,T>& p){ return is >> p.FF >> p.SS; } const double EPS = 1e-10; const double PI = acos(-1.0); const LL MOD = 1e9+7; double C[1010][1010]; double ps[1010], qs[1010]; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); LL x, p; cin >> x >> p; cout << fixed << setprecision(9) << ((x+1)/2) * 100. / p << endl; return 0; /* if(p == 100){ cout << (x+1)/2 << endl; return 0; } if(x > 10) return 1; ps[0] = qs[0] = 1.; REP(i,1000){ ps[i+1] = ps[i] * p / 100.; qs[i+1] = qs[i] * (100-p) / 100.; } for(int i=1;i<1000;++i){ C[i][0] = ps[i]; C[i][i] = qs[i]; for(int j=1;j<i;++j) C[i][j] = C[i-1][j] * qs[1] + C[i-1][j-1] * ps[1]; } const int MAX = 10020; vector<vector<double>> xs(2, vector<double>(MAX)); int crt = 0, nxt = 1; xs[crt][MAX/2+x] = 1.; int px = MAX/2; double ans = 0.; REP(t,MAX/2-20){ fill(ALL(xs[nxt]), 0); REP(a,MAX){ if(a-1 >= 0) xs[nxt][a-1] += xs[crt][a] * p / 100.; if(a+1<MAX) xs[nxt][a+1] += xs[crt][a] * (100.-p) / 100.; } swap(crt, nxt); if(xs[crt][px] < EPS && xs[crt][px-1] < EPS && xs[crt][px+1] < EPS) ++px; else if(xs[crt][px] > xs[crt][px-1] && xs[crt][px] > xs[crt][px+1]) ; else if(xs[crt][px-1] > xs[crt][px] && xs[crt][px-1] > xs[crt][px+1]) --px; else if(xs[crt][px+1] > xs[crt][px-1] && xs[crt][px+1] > xs[crt][px]) ++px; ans += (t+1) * xs[crt][px]; xs[crt][px] = 0.; } cout << fixed << setprecision(9) << ans << endl; */ return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
/* This Submission is to determine how many 120/240 min const. delivery point there are. //info 120 req. steps <= 5 */ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <cstring> #include <queue> #include <stack> #include <math.h> #include <iterator> #include <vector> #include <string> #include <set> #include <math.h> #include <iostream> #include <random> #include<map> #include <iomanip> #include <time.h> #include <stdlib.h> #include <list> #include <typeinfo> #include <list> #include <set> #include <cassert> #include<fstream> #include <unordered_map> #include <cstdlib> #include <complex> #include <cctype> #include <bitset> using namespace std; typedef string::const_iterator State; #define Ma_PI 3.141592653589793 #define eps 1e-5 #define LONG_INF 1e18 #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007 #define MOD 998244353 #define seg_size 262144 #define REP(a,b) for(long long a = 0;a < b;++a) unsigned long xor128() { static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } double dot(complex<double> a, complex<double> b) { return a.real() * b.real() + a.imag() * b.imag(); } double gyaku_dot(complex<double> a, complex<double> b) { return a.real() * b.imag() - a.imag() * b.real(); } double leng(complex<double> a) { return sqrt(a.real() * a.real() + a.imag() * a.imag()); } double angles(complex<double> a, complex<double> b) { double cosine = dot(a, b) / (leng(a) * leng(b)); double sine = gyaku_dot(a, b) / (leng(a) * leng(b)); double kaku = acos(min((double)1.0, max((double)-1.0, cosine))); if (sine <= 0) { kaku = 2 * Ma_PI - kaku; } return kaku; } vector<int> convex_hull(vector<complex<double>> a) { vector<int> ans; double now_minnest = a[0].real(); int now_itr = 0; REP(i, a.size()) { if (now_minnest > a[i].real()) { now_minnest = a[i].real(); now_itr = i; } } ans.push_back(now_itr); complex<double> ba(0, 1); while (true) { int now_go = 0; double now_min = 0; double now_length = 0; int starter = ans[ans.size() - 1]; for (int i = 0; i < a.size(); ++i) { if (i != starter) { double goa = angles(ba, a[i] - a[starter]); if (goa - now_min >= eps || (abs(goa - now_min) <= eps && (abs(a[i] - a[starter]) - now_length) >= eps)) { now_min = goa; now_go = i; now_length = abs(a[i] - a[starter]); } } } if (now_go == ans[0]) break; ans.push_back(now_go); ba = complex<double>(a[now_go] - a[starter]); } return ans; } int main() { double x, p; cin >> x >> p; p /= 100.0; cout << fixed << setprecision(100); cout << ceil(x / 2) / p << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; double calc(int n, int p) { return 100.0 * n / p; } int main() { cin.tie(0); ios::sync_with_stdio(false); int x, p; cin >> x >> p; double ans = 0; if (x % 2 == 0) { ans = calc(x / 2, p); } else { ans = calc((x-1)/2, p) * p / 100 + calc((x+1)/2,p) * (100-p)/100 + 1; } cout << fixed << setprecision(15) << ans << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int X; double P; cin >> X >> P; if(P == 100) cout << (X + 1) / 2 << endl; else cout << fixed << setprecision(10) << (X + 1) / 2 / P * 100.0 << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <cstdio> using namespace std; int main(){ int x, p; while(cin >> x >> p){ int first = (x+1)/2; double prob = 0.01 * p; printf("%.8lf\n", first/prob); } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> using namespace std; long double p; int n; int main() { cin >> n >> p; if (n % 2 == 1)n++; p = 100.0l - p; p /= 100.0l; long double ans = 1.0l*n / (2 - p * 2); printf("%.14Lf\n", ans); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int main(){ int x; cin>>x; if(x%2==1) x++; double p; cin>>p; p/=100; cout<<fixed<<setprecision(10); cout<<x/2/p<<endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ ) #define REP(i,n) FOR(i,0,n) #define YYS(x,arr) for(auto& x:arr) #define ALL(x) (x).begin(),(x).end() #define SORT(x) sort( (x).begin(),(x).end() ) #define REVERSE(x) reverse( (x).begin(),(x).end() ) #define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() ) #define PW(x) (1LL<<(x)) #define SZ(x) ((ll)(x).size()) #define SHOW(x) cout << #x << " = " << x << endl #define pb emplace_back #define fi first #define se second using namespace std; typedef long double ld; typedef long long int ll; typedef pair<int,int> pi; typedef pair<ll,ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<ld> vd; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<vpl> gr; typedef vector<vl> ml; typedef vector<vd> md; typedef vector<vi> mi; const ll INF = (ll)1e9 + 10; const ll INFLL = (ll)1e18 + 10; const ld EPS = 1e-12; const ll MOD = 1e9+7; template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); } template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); } template<class T> inline T sq( T a ){ return a * a; } ll in(){ ll x; scanf( "%lld" , &x ); return x; } char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; } // head int x, ip; int main(){ x = in(); ip = in(); double p = ip / 100.0; printf( "%.18lf\n" , ( x + 1 ) / 2 / p ); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> #define fr first #define sc second #define pb push_back #define ll long long #define maxheap priority_queue<int> #define minheap priority_queue<int,vector<int>,greater<int>> const double pi = acos(-1.0); const double eps = 1e-6; using namespace std; void solve(){ ll x, p; cin >> x >> p; if (x % 2 == 0){ cout << (x / 2) * (100. / p) << endl; }else{ cout << ((x + 1) / 2) * (100. / p) << endl; } } int main(){ ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); cout.setf(ios::fixed), cout.precision(5); //freopen("input.txt", "r", stdin);//freopen("output1.txt", "w", stdout); //freopen("icecream.in","r",stdin);// freopen("exam.out", "w", stdout); int step; step = 1; //cin >> step; for (int i = 1; i <= step; i++){ solve(); } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(ut)(b);i++) #define REP(i,b) FOR(i,0,b) #define ALL(c) c.begin(),c.end() #define PB push_back #define cat //cout << __LINE__ << endl; using namespace std; typedef long long LL; typedef double ld; typedef int ut; typedef vector<ut> VI; typedef pair<ut,ut> pr; typedef pair<ut,pr> ppr; typedef vector<pr> Vpr; typedef vector<ppr> Vppr; typedef priority_queue<pr,Vpr,greater<pr> > PQ; using namespace std; const int SIZE=1e6; const LL INF=1LL<<58; const LL p=1e9+7; vector<string> nums; int K; string s; double per; double solve(LL x,LL p){ if(x&1){return 1+solve(x-1,p)*per+solve(x+1,p)*(1-per);} double need=x/2; return need/per; } int main(){ LL x,p; cin >> x >> p; per=p/100.0; printf("%12.12f\n",solve(x,p)); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include "iostream" #include "iomanip" using namespace std; long double X; long double rad; long double ans; int main() { cin >> X >> rad; if ((long long int)X % 2 == 0) { for (int i = 0; i < 10000000; i++) { ans = (ans + X - rad / 100 * ans + (100.0 - rad) / 100 * ans) / 2; } } else { for (int i = 0; i < 10000000; i++) { ans = (ans+1 + X - rad / 100 * ans + (100.0 - rad) / 100 * ans) / 2; } } cout << setprecision(15) << ans; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <climits> #include <ctime> #include <cassert> using namespace std; #define rep(i,a,n) for(int i=a; i<n; i++) #define repq(i,a,n) for(int i=a; i<=n; i++) #define repr(i,a,n) for(int i=a; i>=n; i--) #define pb(a) push_back(a) #define fr first #define sc second #define INF 2000000000 #define int long long int #define X real() #define Y imag() #define EPS (1e-10) #define EQ(a,b) (abs((a) - (b)) < EPS) #define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) ) #define LE(n, m) ((n) < (m) + EPS) #define LEQ(n, m) ((n) <= (m) + EPS) #define GE(n, m) ((n) + EPS > (m)) #define GEQ(n, m) ((n) + EPS >= (m)) typedef vector<int> VI; typedef vector<VI> MAT; typedef pair<int, int> pii; typedef long long ll; typedef complex<double> P; typedef pair<P, P> L; typedef pair<P, double> C; int dy[]={0, 0, 1, -1}; int dx[]={1, -1, 0, 0}; int const MOD = 1000000007; namespace std { bool operator<(const P& a, const P& b) { return a.X != b.X ? a.X < b.X : a.Y < b.Y; } } signed main() { int x, p; cin >> x >> p; cout << fixed << setprecision(10) << ((x - 1) / 2 + 1) / (double)p * 100.0 << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
python3
x = int(input()) p = int(input()) p *= 0.01 print((x+1)//2/p)
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
python3
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # 偶奇をあわせて寄せていくだけ X,P = map(int,read().split()) def f(x): y = x // 2 return y * 100 / P if X % 2 == 0: answer = f(X) else: answer = 1 + (P * f(X-1) + (100-P) * f(X+1))/100 print(answer)
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cout << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cout<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 200010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = 1 << 29; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; /////////////////////////////////////////////////////////////////////////////////////////////////// int N, P; void solve() { cin >> N >> P; if(N % 2 == 0) { cout << (N / 2) * (100.0 / P); } else { cout << (N - 1) / 2 + (100.0 - P) / P * (N + 1) / 2 + 1.0; } } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); srand((unsigned int)time(NULL)); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define _overload(_1,_2,_3,name,...) name #define _rep(i,n) _range(i,0,n) #define _range(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__) #define _rrep(i,n) _rrange(i,n,0) #define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i) #define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__) #define _all(arg) begin(arg),end(arg) #define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg)) #define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary) #define clr(a,b) memset((a),(b),sizeof(a)) #define bit(n) (1LL<<(n)) #define popcount(n) (__builtin_popcountll(n)) using namespace std; template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;} template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;} using ll = long long; using R = long double; const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7 inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);} inline R sq(R x) {return sqrt(max(x, 0.0L));} const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; // Problem Specific Parameter: int main(void) { ll x, t; cin >> x >> t; const R p = 1.0 * t / 100.0; const R q = 1.0 - p; R ans = 1.0 * (x / 2) / p; if (x % 2 == 1) ans += q / p + 1.0; cout.precision(20); cout << fixed << ans << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; long double f(int x, long double p) { if(x % 2 == 1){ return p * f(x - 1, p) + (1 - p) * f(x + 1, p) + 1; } return (x / 2) * (1 / p); } int main() { cout.precision(10); int x; long double p; cin >> x >> p; p = p / 100; cout << f(x, p) << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
python3
from sys import exit, setrecursionlimit from functools import reduce from itertools import * from collections import defaultdict from bisect import bisect def read(): return int(input()) def reads(): return [int(x) for x in input().split()] setrecursionlimit(1000000) x = read() p = read() p *= 0.01 if x % 2 == 0: print((x // 2) / p) else: y = x // 2 print(1 + p * y / p + (1 - p) * (y + 1) / p)
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
/** * author: tourist * created: 26.11.2019 09:30:33 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int x; cin >> x; double p; cin >> p; p *= 0.01; if (x % 2 == 1) { cout << fixed << setprecision(17) << (x + 1) / 2 / p << '\n'; } else { cout << fixed << setprecision(17) << x / 2 / p << '\n'; } return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> int main() { long long x; int p; scanf("%lld%d",&x,&p); printf("%lf\n",(x+1)/2*(double)100./p); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> using namespace std; typedef long long ll; typedef unsigned int ui; const ll MOD = 998244353; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-11; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; typedef pair<ld, ld> LDP; int main() { ll x; int p; cin >> x >> p; cout << fixed << setprecision(7); if (x % 2) { cout << (ld)50 * (x + 1) / p << endl; } else { cout << (ld)50 * x / p << endl; } return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<fstream> #include<algorithm> #include<vector> #include<queue> #include<map> #include<set> #include<string> #include<cmath> using namespace std; #define REP(i,m,n) for(int i=(m); i<(int)(n); i++) #define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--) #define rep(i,n) REP(i,0,n) #define rrep(i,n) RREP(i,0,n) #define fi first #define se second #ifdef _DEBUG ifstream ifs("input"); #define input ifs #else #define input cin #endif #define DEBUG(x) cout<<#x<<": "<<x<<endl using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const double PI = (1*acos(0.0)); const double INF = 1e9; const double EPS = 1e-9; const double mod = 1e9 + 7; int main(){ int x,p; input >> x >> p; printf("%.7lf", ceil(x/2.0) * (100.0/p)); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; const int INF = 1e9; const ld EPS = 1e-8; int main(){ int x, p; cin >> x >> p; long double res = ((x + 1) / 2) / (p / 100.0); cout << fixed << setprecision(10) << res << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false), cin.tie(0); int x, pp; cin >> x >> pp; double p = pp / 100.0; double ans; if(x % 2) { ans = 1 + (1 / p) * (x / 2) + (1 / p) * (1 - p); } else { ans = (1 / p) * (x / 2); } cout << fixed << setprecision(7) << ans << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <cassert> #include <cctype> #include <cstdlib> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <utility> #define reps(i,f,n) for(int i=f; i<int(n); ++i) #define rep(i,n) reps(i,0,n) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; const int INF = 1001001001; signed main() { int x, p; cin >> x >> p; cout << setprecision(15) << (x+1)/2 * 100.0 / p << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define DEBUG_MODE #define endl '\n' #ifdef DEBUG_MODE #define DEBUG(...) debug_func_mult(split_names(#__VA_ARGS__), __VA_ARGS__) #define DEBUG_ENDL endl << flush #define DEBUG_SEPARATOR_LINE cout<<"=================\n" #else #define DEBUG(...) 0 #define DEBUG_ENDL 0 #define DEBUG_SEPARATOR_LINE 0 #endif #define ALL(V) (V).begin(), (V).end() #define ALLR(V) (V).rbegin(), (V).rend() #define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush; template <typename T> using V = vector<T>; template <typename T> using VV = V<V<T>>; template <typename T, typename U> using P = pair<T, U>; using ll = int64_t; using PLL = P<ll, ll>; template <typename T> const T& var_min(const T &t) { return t; } template <typename T> const T& var_max(const T &t) { return t; } template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); } template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); } template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } string to_string(const string &s) { return s; } template <typename T, typename U> string to_string(const P<T, U> &p) { string ret = "("; ret += to_string(p.first); ret += ", "; ret += to_string(p.second); ret += ")"; return move(ret); } template <typename T> string to_string(const V<T> &v) { string ret = "{"; for(const T &t : v) { ret += to_string(t); ret += ", "; } ret += "}"; return move(ret); } template <typename T> void debug_func(const T &t, const string &s = "") { if(s.size()) cout << s << " = "; cout << to_string(t) << DEBUG_ENDL_S(s); } template <typename T> void debug_func_mult(int idx, const V<string> &names, const T &t) { debug_func(t, names[idx]); } template <typename T> void debug_func_mult(const V<string> &names, const T &t) { debug_func(t, names[0]); } template <typename Head, typename... Tail> void debug_func_mult(int idx, const V<string> &names, const Head &head, const Tail&... args) { debug_func(head, names[idx]); debug_func_mult(idx + 1, names, args...); } template <typename Head, typename... Tail> void debug_func_mult(const V<string> &names, const Head &head, const Tail&... args) { debug_func(head, names[0]); debug_func_mult(1, names, args...); } V<string> split_names(string &&s) { replace(ALL(s), ' ', ','); V<string> ret; istringstream ss(s); string t; while(getline(ss, t, ',')) if(t.size()) ret.push_back(move(t)); return move(ret); } void init_io() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } double calc(double P, ll cnt) { if(cnt == 0) return 0; return (cnt / 2) / P; } int main() { init_io(); ll X; double P; cin >> X >> P; P /= 100; if(X & 1) cout << P * (calc(P, X - 1) + 1) + (1 - P) * (calc(P, X + 1) + 1); else cout << calc(P, X); cout << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#pragma region include #include <iostream> #include <iomanip> #include <stdio.h> #include <sstream> #include <algorithm> #include <iterator> #include <cmath> #include <complex> #include <string> #include <cstring> #include <vector> #include <tuple> #include <bitset> #include <queue> #include <complex> #include <set> #include <map> #include <stack> #include <list> #include <fstream> #include <random> //#include <time.h> #include <ctime> #pragma endregion //#include ///////// #define REP(i, x, n) for(int i = x; i < n; ++i) #define rep(i,n) REP(i,0,n) #define ALL(X) X.begin(), X.end() ///////// #pragma region typedef typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef std::pair<LL,LL> PLL;// typedef std::pair<int,int> PII;// #pragma endregion //typedef ////定数 const int INF = (int)1e9; const LL MOD = (LL)1e9+7; const LL LINF = (LL)1e18+20; const LD PI = acos(-1.0); const double EPS = 1e-9; ///////// using namespace::std; void solve(){ int X; double P; cin >> X >> P; if( P == 100 ){ double ans = (X+1)/2; cout << ans << endl; return; } if( X <= 10 ){ double p = P/100; double q = 1-p; if( X%2 == 0 ){//Xが偶数 vector<double> dp(X+10,0); dp[0] = 0.0;//距離が0の時の期待値 int now = 0; for(;now<X;now += 2 ){ dp[now+2] = dp[now] + 1.0/p; } double ans = dp[X]; cout << ans << endl; return; }else{//距離Xが奇数 vector<double> dp(X+20,0); dp[0] = 0.0; int now = 0; for(;now<X+4; now += 2 ){ dp[now+2] = dp[now] + 1.0/p; } double ans = dp[X-1]*p + dp[X+1]*q + 1.0;///// cout << ans << endl; return; } return; } if( X&1 ){//奇数 double p = P/100; double q = 1-p; double cnt1 = (X-1)/2; double cnt2 = (X+1)/2; double res1 = (1.0/p) * cnt1; double res2 = (1.0/p) * cnt2; double ans = res1 * p + res2 * q + 1.0; cout << ans << endl; }else{//偶数 double p = P/100; double q = 1-p; double cnt = X/2;//cnt回pを引き当てる。 //pを1回引くまでの、試行回数の期待値は1/p double ans = (1.0/p) * cnt; cout << ans << endl; } } #pragma region main signed main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;//小数を10進数表示 cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別 solve(); } #pragma endregion //main()
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; double f(int p, int n) { double P = p/100.0; double Q = 1.0 - P; double ans = (-n)/(2*(Q-1)); return ans; } int main() { int x,p; cin>>x>>p; cout.precision(10); double ans; if(x%2) ans = 1.0 + (p/100.0)*f(p,x-1) + ((100 - p)/100.0)*f(p,x+1); else ans = f(p,x); cout<<fixed<<ans<<"\n"; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#ifndef KOMAKI_LOCAL #define NDEBUG #endif #include <bits/stdc++.h> #include <sys/time.h> #include <unistd.h> using namespace std; #define i64 int64_t #define rep(i, n) for(i64 i = 0; i < ((i64)(n)); ++i) #define sz(v) ((i64)((v).size())) #define bit(n) (((i64)1)<<((i64)(n))) #define all(v) (v).begin(), (v).end() std::string dbgDelim(int &i){ return (i++ == 0 ? "" : ", "); } #define dbgEmbrace(exp) { int i = 0; os << "{"; { exp; } os << "}"; return os; } template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> v); template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> v); template <class T> std::ostream& operator<<(std::ostream &os, std::queue<T> q); template <class T> std::ostream& operator<<(std::ostream &os, std::priority_queue<T> q); template <class T, class K> std::ostream& operator<<(std::ostream &os, std::pair<T, K> p); template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> mp); template <class T, class K> std::ostream& operator<<(std::ostream &os, std::unordered_map<T, K> mp); template <int INDEX, class TUPLE> void dbgDeploy(std::ostream &os, TUPLE tuple){} template <int INDEX, class TUPLE, class H, class ...Ts> void dbgDeploy(std::ostream &os, TUPLE t) { os << (INDEX == 0 ? "" : ", ") << get<INDEX>(t); dbgDeploy<INDEX + 1, TUPLE, Ts...>(os, t); } template <class T, class K> void dbgDeploy(std::ostream &os, std::pair<T, K> p, std::string delim) { os << "(" << p.first << delim << p.second << ")"; } template <class ...Ts> std::ostream& operator<<(std::ostream &os, std::tuple<Ts...> t) { os << "("; dbgDeploy<0, std::tuple<Ts...>, Ts...>(os, t); os << ")"; return os; } template <class T, class K> std::ostream& operator<<(std::ostream &os, std::pair<T, K> p) { dbgDeploy(os, p, ", "); return os; } template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> v) { dbgEmbrace( for(T t: v){ os << dbgDelim(i) << t; }); } template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> s) { dbgEmbrace( for(T t: s){ os << dbgDelim(i) << t; }); } template <class T> std::ostream& operator<<(std::ostream &os, std::queue<T> q) { dbgEmbrace( for(; q.size(); q.pop()){ os << dbgDelim(i) << q.front(); }); } template <class T> std::ostream& operator<<(std::ostream &os, std::priority_queue<T> q) { dbgEmbrace( for(; q.size(); q.pop()){ os << dbgDelim(i) << q.top(); }); } template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> mp) { dbgEmbrace( for(auto p: mp){ os << dbgDelim(i); dbgDeploy(os, p, "->"); }); } template <class T, class K> std::ostream& operator<<(std::ostream &os, std::unordered_map<T, K> mp) { dbgEmbrace( for(auto p: mp){ os << dbgDelim(i); dbgDeploy(os, p, "->"); }); } #define DBG_OUT std::cerr #define DBG_OVERLOAD(_1, _2, _3, _4, _5, _6, macro_name, ...) macro_name #define DBG_LINE() { char s[99]; sprintf(s, "line:%3d | ", __LINE__); DBG_OUT << s; } #define DBG_OUTPUT(v) { DBG_OUT << (#v) << "=" << (v); } #define DBG1(v, ...) { DBG_OUTPUT(v); } #define DBG2(v, ...) { DBG_OUTPUT(v); DBG_OUT << ", "; DBG1(__VA_ARGS__); } #define DBG3(v, ...) { DBG_OUTPUT(v); DBG_OUT << ", "; DBG2(__VA_ARGS__); } #define DBG4(v, ...) { DBG_OUTPUT(v); DBG_OUT << ", "; DBG3(__VA_ARGS__); } #define DBG5(v, ...) { DBG_OUTPUT(v); DBG_OUT << ", "; DBG4(__VA_ARGS__); } #define DBG6(v, ...) { DBG_OUTPUT(v); DBG_OUT << ", "; DBG5(__VA_ARGS__); } #define DEBUG0() { DBG_LINE(); DBG_OUT << std::endl; } #define DEBUG(...) \ { \ DBG_LINE(); \ DBG_OVERLOAD(__VA_ARGS__, DBG6, DBG5, DBG4, DBG3, DBG2, DBG1)(__VA_ARGS__); \ DBG_OUT << std::endl; \ } int main() { i64 x; double p; cin >> x >> p; p /= 100; printf("%0.20lf\n", (x + 1) / 2 * (1.0 / p)); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <string> #include <deque> #include <map> #include <set> #include <cassert> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define fi first #define se second #define sz(x) ((int)(x).size()) #define It iterator typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; int main() { //freopen("test.in","r",stdin); ll x,p; cin>>x>>p; double xx=x/2+x%2; printf("%.6f",xx/p*100); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <stdio.h> #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long #define rep2(i,a,b) for(ll i=a;i<=b;++i) #define rep(i,n) for(ll i=0;i<n;i++) #define rep3(i,a,b) for(ll i=a;i>=b;i--) #define REP(e,v) for(auto e:v) #define pii pair<int,int> #define pll pair<ll,ll> #define tii tuple<int,int,int> #define pq priority_queue<int> #define pqg priority_queue<int,vector<int>,greater<int>> #define pb push_back #define edge(v,a,b) v[a].pb(b);v[b].pb(a); #define MAX_V 400010 #define vec vector<int> #define vecll vector<ll> #define vecpii vector<pii> #define endl "\n" #define ALL(c) (c).begin(),(c).end() using namespace std; int in() {int x;scanf("%d",&x);return x;} ll lin() {ll x;scanf("%lld",&x);return x;} #define INF 1e9+7 #define LLINF 1e18+7 ll MOD=1e9+7; #define N 1055050 int main(){ ll x=in(); double p=in(); ll ans=0; if(x%2)x++; double xx=x; xx/=2.0; printf("%.10f\n",xx/p*100.0); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; double x, p; int main() { cin >> x >> p; double res = floor((x + 1) / 2) / (p / 100); printf("%.8f", res); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; // #define int long long #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define LLINF 10000000000000ll #define fi first #define sec second #define all(x) (x).begin(),(x).end() #define sq(x) ((x)*(x)) #define dmp(x) cerr << #x << ": " << x << endl; template<class T> void chmin(T& a,const T& b){if(a>b)a=b;} template<class T> void chmax(T& a,const T& b){if(a<b)a=b;} template<class T> using MaxHeap = priority_queue<T>; template<class T> using MinHeap = priority_queue<T,vector<T>,greater<T> >; template<class T,class U> ostream& operator << (ostream& os,const pair<T,U>& p){ os << p.fi << ',' << p.sec; return os; } template<class T,class U> istream& operator >> (istream& is,pair<T,U>& p){ is >> p.fi >> p.sec; return is; } template<class T> ostream& operator << (ostream &os,const vector<T> &vec){ for(int i=0;i<vec.size();i++){ os << vec[i]; if(i+1<vec.size())os << ' '; } return os; } template<class T> istream& operator >> (istream &is,vector<T>& vec){ for(int i=0;i<vec.size();i++)is >> vec[i]; return is; } void fastio(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); } namespace Math{ template<int MOD> // if inv is needed, this shold be prime. struct ModInt{ ll val; ModInt():val(0ll){} ModInt(const ll& v):val(((v%MOD)+MOD)%MOD){} ModInt pow(ModInt a,ll x){ ModInt res = ModInt(1ll); while(x){ if(x&1)res *= a; x >>= 1; a = a*a; } return res; } bool operator==(const ModInt& x)const{return val==x.val;} bool operator!=(const ModInt& x)const{return !(*this==x);} bool operator<(const ModInt& x)const{return val<x.val;} bool operator>(const ModInt& x)const{return val>x.val;} bool operator>=(const ModInt& x)const{return !(*this<x);} bool operator<=(const ModInt& x)const{return !(*this>x);} ModInt& operator+=(const ModInt& x){if((val+=x.val)>=MOD)val-=MOD;return *this;} ModInt& operator-=(const ModInt& x){if((val+=MOD-x.val)>=MOD)val-=MOD;return *this;} ModInt& operator*=(const ModInt& x){(val*=x.val)%=MOD;return *this;} ModInt operator+(const ModInt& x)const{return ModInt(*this)+=x;} ModInt operator-(const ModInt& x)const{return ModInt(*this)-=x;} ModInt operator*(const ModInt& x)const{return ModInt(*this)*=x;} friend istream& operator>>(istream&i,ModInt& x){ll v;i>>v;x=v;return i;} friend ostream& operator<<(ostream&o,const ModInt& x){o<<x.val;return o;} }; constexpr int MOD = 1e9+7; using mint = ModInt<MOD>; vector<mint> inv,fac,facinv; // notice: 0C0 = 1 ModInt<MOD> nCr(int n,int r){ assert(!(n<r)); assert(!(n<0||r<0)); return fac[n]*facinv[r]*facinv[n-r]; } void init(int SIZE){ fac.resize(SIZE+1); inv.resize(SIZE+1); facinv.resize(SIZE+1); fac[0] = inv[1] = facinv[0] = mint(1ll); for(int i=1;i<=SIZE;i++)fac[i]=fac[i-1]*mint(i); for(int i=2;i<=SIZE;i++)inv[i]=mint(0ll)-mint(MOD/i)*inv[MOD%i]; for(int i=1;i<=SIZE;i++)facinv[i]=facinv[i-1]*inv[i]; return; } } namespace DS{ template<class T> struct RangeSum{ vector<T> vec; RangeSum(){} RangeSum(vector<T> elems):vec(elems){ for(int i=1;i<vec.size();i++){ vec[i] += vec[i-1]; } } T sum(int l,int r){ if(l>r)return T(0); if(l==0)return vec[r]; else return vec[r]-vec[l-1]; } }; template<class T,int N> struct BIT{ vector<T> bit; BIT(){ bit = vector<T>(N+1,T(0)); } void add(int i,T x){ i++; while(i<=N){ bit[i]+=x; i+=i&-i; } return; } T sum(int i){ i++; T res = T(0); while(i>0){ res+=bit[i]; i-=i&-i; } return res; } T sum(int l,int r){// [l,r] assert(l<=r); if(l==0)return sum(r); else return sum(r)-sum(l-1); } }; } signed main(){ fastio(); int x,p; cin >> x >> p; if(x&1)x++; cout << x/2.0*100.0/(double)p << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <iomanip> using namespace std; double p; int x; int main(){ cin >> x >> p; p /= 100; if(x%2==1) x++; cout << setprecision(8) << x/(2*p) << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> typedef long long i64; using std::cout; using std::endl; using std::cin; int main() { int x, p; cin >> x >> p; cout << std::fixed << std::setprecision(10); cout << (double)((x + 1) / 2) / (p / 100.) << endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <iomanip> // << fixed << setprecision(xxx) #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <vector> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <complex> #include <tuple> // get<n>(xxx) #include <queue> #include <stack> #include <map> // if (M.find(key) != M.end()) { } #include <set> // S.insert(M); // if (S.find(key) != S.end()) { } // for (auto it=S.begin(); it != S.end(); it++) { } // auto it = S.lower_bound(M); #include <cctype> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> // atoi(xxx) using namespace std; typedef long long ll; //const int dx[4] = {1, 0, -1, 0}; //const int dy[4] = {0, 1, 0, -1}; // const int C ; // const int M = 1000000007; int main () { ll x; int p; cin >> x >> p; if (x%2 == 1) { x++; } double pp = p/(double)100; double vec = -1 * pp + (1-pp); vec -= 1; cout << fixed << setprecision(12) << x/(-1 * vec) << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main(){ LL x, p1; cin >> x >> p1; double p = ((double)p1) / 100.0; if(x % 2) x++; x /= 2; double r = ((double)x)/p; printf("%.9lf\n", r); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<cstdio> #include<algorithm> #include<set> #include<map> #include<queue> #include<cassert> #include<iomanip> #define PB push_back #define MP make_pair #define sz(v) (in((v).size())) #define forn(i,n) for(in i=0;i<(n);++i) #define forv(i,v) forn(i,sz(v)) #define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i) #define all(v) (v).begin(),(v).end() using namespace std; typedef long long in; typedef vector<in> VI; typedef vector<VI> VVI; double t(in x, double p){ in tt=x/2; double tpt=1/p; return tt*tpt; } int main(){ ios::sync_with_stdio(0); cin.tie(0); in x; double p; cin>>x>>p; p/=100; cout<<setprecision(15); if(x%2!=0) cout<<1+p*t(x-1,p)+(1-p)*t(x+1,p)<<endl; else cout<<t(x,p)<<endl; return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <iostream> #include <string> #include <vector> #include <sstream> #include <map> #include <set> #include <queue> #include <algorithm> #include <cmath> #include <cstring> #include <typeinfo> #include <numeric> #include <functional> #include <unordered_map> #include <bitset> #include <stack> #include <assert.h> #include <unordered_set> using namespace std; using ll = long long; using ull = unsigned long long; const ll INF = 1e16; const ll MOD = 1e9 + 7; #define REP(i, n) for(ll i = 0; i < n; i++) int main(){ int x; double p; cin >> x >> p; p /= 100.0; double xx = (x + 1) / 2; printf("%.11lf\n", xx / p); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() const int mod=1000000007,MAX=4003,INF=1<<30; int main(){ long double X,P;cin>>X>>P; if(int(X)%2==0){ cout<<setprecision(25)<<100.0/P*(X/2.0)<<endl; }else{ cout<<setprecision(25)<<(P/100.0)*(100.0/P)*((X-1.0)/2.0)+((100.0-P)/100.0)*(100.0/P)*((X+1.0)/2.0)+1.0<<endl; } }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> int x, p; int main() { scanf("%d %d", &x, &p); printf("%.12lf\n", 50.0 * (x + x % 2) / p); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <iomanip> using namespace std; int main(){ int x, p; cin >> x >> p; double ans; if(x%2 == 0){ ans = ((double)(x/2))*((double)(100)/(double)(p)); }else{ ans = ((double)((x+1)/2))*((double)(100)/(double)(p)); } cout << fixed; cout << setprecision(9) << ans << endl; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define mod 998244353 using namespace std; typedef pair<llint, llint> P; typedef pair<llint, P> E; llint x; double p; double calc(llint x) { return 1/p*x; } int main(void) { cin >> x; cin >> p; p /= 100; double ans; if(x % 2 == 0) ans = calc(x/2); else ans = 1 + p*calc((x-1)/2) + (1-p)*calc((x+1)/2); printf("%.11f\n", ans); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<vvd> vvvd; typedef pair<int, int> pii; typedef vector<pii> vpii; #define pb push_back #define mp make_pair #define snd second #define fst first #define debug printf("--%d--\n",__LINE__) #define ll long long int int x, p; int main(void){ cin >> x >> p; int n = (abs(x)+1)/2; int q = ((x>0) ? p : 100-p); double pr = 0.01 * q; printf("%.8f\n", n / pr); return 0; }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) double rec(int x, double p) { if (x % 2) return p * rec(x - 1, p) + (1 - p) * rec(x + 1, p) + 1; return x / p / 2; } //----------------------------------------------------------------- int main() { int x, p; cin >> x >> p; double ans = rec(x, p / 100.0); printf("%.10f\n", ans); }
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously: * Let the current coordinate of Aoki be a, then Aoki moves to a coordinate he selects from a-1, a and a+1. * Let the current coordinate of Takahashi be b, then Takahashi moves to the coordinate b-1 with probability of p percent, and moves to the coordinate b+1 with probability of 100-p percent. When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi. When they pass by each other, Aoki cannot find Takahashi. Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns. Constraints * 1 ≦ x ≦ 1,000,000,000 * 1 ≦ p ≦ 100 * x and p are integers. Input The input is given from Standard Input in the following format: x p Output Print the minimum possible expected number of turns. The output is considered correct if the absolute or relative error is at most 10^{-6}. Examples Input 3 100 Output 2.0000000 Input 6 40 Output 7.5000000 Input 101 80 Output 63.7500000
{ "input": [ "6\n40", "101\n80", "3\n100" ], "output": [ "7.5000000", "63.7500000", "2.0000000" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <unordered_map> using namespace std; typedef long long int ll; typedef pair<int, int> P; int main() { ll x; double p; cin>>x>>p; if(x%2) printf("%.7lf\n", ((double)x+1)/2/p*100); else printf("%.7lf\n", ((double)x)/2/p*100); return 0; }