Блог пользователя chokudai

Автор chokudai, история, 6 лет назад, По-английски

We will hold AtCoder Beginner Contest 169.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +85
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -25 Проголосовать: не нравится

Editorial in english must also be posted as soon as in japanese.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

I hope it would be a great Contest

»
6 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +9 Проголосовать: не нравится

Excited that I will learn something new!

Update: Learned when to use double when not to use doubles and how to use doubles!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -80 Проголосовать: не нравится

2nd and the 3rd question seems easy but is really tricky... i dont know on which cases my code is getting wa...can anyone please help

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -23 Проголосовать: не нравится

I'm so sad, it took me less time to D than it took me to do B and I haven't even done C. Everytime, I miss one of B-D. I'm cursed D:

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Will a CE submission be calculated into the overall penalty?

I submitted two pieces of codes in the wrong language and will my overall penalty increase by 10 min?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

How to solve F?

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

How to solve E!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In the second part, there are essentially two tricks for the problem 1) Sort the array. If the value at index i is 0, then we cannot return -1(no matter what). 2) Multiplying two extremely large numbers even when the data type is long long int will result in negative values, which will result in wrong answers. So, a*b>=c is equivalent to b>=(c/a)(take care of the border cases) Link to my code https://atcoder.jp/contests/abc169/submissions/13810433

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Okay, so in the 3rd question, I simply multiplied a and b, and applied the floor function for the product. Link to my code in C++ https://atcoder.jp/contests/abc169/submissions/13814577

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

I just wonder how to solve B,C...

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i was getting TLE Second Question

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I'm guessing you may have tried to multiply all the numbers together in Python or a similar language? Since the intermediate products can have $$$O(N)$$$ digits, multiplying them takes $$$O(N)$$$ time, so this approach takes $$$O(N^2)$$$ time in the worst case.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +29 Проголосовать: не нравится

My solutions to all problems are at https://codeforces.me/blog/entry/78195.

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please tell why this fails for C?

n = input().split()
i1 = int(n[0])
i2 = int(float(n[1]) * 100.0)
i = i1 * i2
print(i // 100)
»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

In C, why is math.trunc(a*b) in python giving WA,but in CPP, this is accepted-

ll a;
long double b;
cin>>a>>b;
ll ans;
ans=a*b;
cout<<ans;
»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

nvm, got it

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -7 Проголосовать: не нравится

can anybody find mistake in my D solution.

#include<bits/stdc++.h>
using namespace std; 
bool ispower(int x,set<int> s)
{
	int f=0;
	int p=1;
	while(x%2==0)
	{
		p*=2;
		x=x/2;
		f=1;
	}
	if(x==1 && s.find(p)==s.end())return true;
	if(f==1)return false;
	int t=sqrt(x);
	for(int i=3;i<=t;i+=2)
	{
		int p=1;
		while(x%i==0)
		{
			f=1;
			x=x/i;
			p*=i;
		}
		if(f==1 && x==1 && s.find(p)==s.end())return true;
		if(f==1)return false;
	}
	return false;
}
bool isprime(int x)
{
	for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
	return true;
}
int main()
{
	
	long long x;
	cin>>x;
	long long ans=0;
	int r=sqrt(x);
	set<int> s;
	bool seive[r+1];
	for(int i=2;i<=r;i++)seive[i]=true;
	for(int i=2;i<=r;i++)
	{
		if(seive[i])
		{
			for(int j=i;j<=r;j*=i)
			{
				if(x%j==0)
				{
					x=x/j;
					ans++;
					s.insert(j);
				}
			}
			for(int j=2*i;j<=r;j+=i)
			{
				seive[j]=false;
			}
		}
	}
	if(x>=2 && s.find(x)==s.end() && (ispower(x,s) || isprime(x)))ans++;
	cout<<ans;
	return 0;
}
»
6 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Any care to explain why is this wrong for problem C ?


#define int long long void solve() { int a,b; double c; cin >> a; cin >> c; b = (c*100); int res = (a*b); res/=100; cout << res; }

It gives WA for random_12.txt

Edit : I always define int as long long in my template.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In the fourth question, I simply used the Sieve of Eratosthenes to get the prime numbers less than 1e6, after that I iterate from 2 to the largest prime less than 1e6, and simply code out for the number of ways the number can be broken down! Just be careful when we multiply two numbers of digits 5 and 6! Link to my code- https://atcoder.jp/contests/abc169/submissions/13855795

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve c? I multiplied a*b and took floor(a*b). What's wrong? submission

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Please someone help me out with Problem C ....... My Submission

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Whats wrong wit C

import java.math.BigDecimal; import java.util.Scanner;

public class Main {

public static void main(String args[])
{
    Scanner sc=new Scanner(System.in);
    long a=sc.nextLong();
    long b=(long)(sc.nextDouble()*100);
    long ans=(a*b)/100;
    System.out.println(ans);

}
»
6 лет назад, скрыть # |
← Rev. 7  
Проголосовать: нравится +19 Проголосовать: не нравится

I usually get one hit on both Codeforces and Atcoder, but this time seems horrible xD

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Whats wrong in D

import java.util.Scanner;

public class Main {

public static void main(String args[])
{
    Scanner sc=new Scanner(System.in);
   long n=sc.nextLong();
   long copyn=n;
   long x=(long)Math.sqrt(n);
   long copyx=x;
   long ans=0;
   for(int i=2;i<=x;i++)
   {
       int count=1;
       while(n%((Math.pow(i,count)))==0)
       {

           n= (long) (n/Math.pow(i,count));
           count++;
           ans++;
       }

       while(n%(Math.pow(i,count))==0)
       {
           n= (long) (n/Math.pow(i,count));
       }
   }

   if(copyn==1)
   {
       System.out.println(0);
   }
   else

   if(n>x)
   {
       System.out.println(1+ans);
   }
   else
   {
       System.out.println(ans);
   }

}

}

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -15 Проголосовать: не нравится

What is the problem with this solution of C?Can someone help?

include<bits/stdc++.h>

using namespace std; typedef long long ll;

define mod 1000000007

int main() { ll a; float b1; cin>>a>>b1;
b1=b1*100; ll b=b1; ll s=a*b; s=s/100; printf("%lld\n",s); }

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://atcoder.jp/contests/abc169/submissions/13900202 [WA] https://atcoder.jp/contests/abc169/submissions/13900438 [AC]

Both are identical solutions for problem B of AtCoder Beginner Contest 169. Does anyone knows why this happen?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think I got a beautiful solution for F: the answer is just the coefficient of x^s in polynominal (2 + x^a1)(2 + x^a2)...(2 + x^an) here '^' is for power. we can just ignore higher order coefficient than x^s.

https://atcoder.jp/contests/abc169/submissions/13847100

please ignore unremoved code for problem D, E.

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

In B:
For the statement: if(inp[i] <= 1e18/ans) I got WA. But when i wrote : if(inp[i] <= 1000000000000000000/ans) I got AC. Is there any differences between 1e18 and 1000000000000000000?? Otherwise what is the reason??

»
6 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +8 Проголосовать: не нравится

In editorial there is a typo in problem D English version.

Wrong:$$$O(N)$$$

Correct:$$$O(sqrt(N))$$$

Capture.png

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Can AnyBody please tell how can i reduce the submission time of my solution to the problem F?

https://atcoder.jp/contests/abc169/submissions/13920879

I have seen people getting AC in less than 100ms while mine is giving AC in 1000 ms.

thanks in advance. :).

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In the editorial of problem F it says:

dp[i][j] = When the choices for the first i options is already determined, the number of combination such that the sum of ak for each k that the first option was chosen is equal to j

What does it even mean?

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone help me debug my solution? I get TLE on 6-7 test cases, no idea why. Thank you!

#include <iostream>
#include <vector>
using namespace std;

int solve(long long n) {
    if (n == 1) {
        return 0;
    }
    vector<int> f;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            f.push_back(i);
            n /= i;
        }
    }
    if (n > 1) f.push_back(n);

    int ans = 0;
    int i = 0;
    while (i < f.size()) {
        int j = i + 1;
        while (j < f.size() && f.at(j) == f.at(i)) j++;
        int count = j - i;
        i = j;
        int sum = 0;
        for (int x = 1; count >= sum + x; x++, ans++) sum += x;
    }
    return ans;
}

int main() {
    long long n;
    cin >> n;
    cout << solve(n) << endl;
}
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

what is my wrong with my code in problem-c? https://atcoder.jp/contests/abc169/submissions/13926562

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For problem D, Maybe this sounds stupid, But can someone please explain why is it optimal to compute for each prime and its powers first, then similarly with next prime and its powers, and so on instead of going from 2 onwards ?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone provide any proof for problem-E for both odd and even case.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    If we increase one value by $$$1$$$ and leave the rest as it is, then median can stay the same or increase by $$$1$$$ for odd $$$n$$$ and stay the same or increase by \frac{1}{2}

    Unable to parse markup [type=CF_MATHJAX]

    is even. Now let's set $$$X_i = A_i$$$ and increase all of them one by one till we reach $$$X_i = B_i$$$. At first median equals median of $$$A_i$$$, and after all operations equals median of $$$B_i$$$ and at each step it will either stay the same or increase by $$$1$$$ in case of odd $$$n$$$ and by $$$\frac 12$$$ for even $$$n$$$ thus will reach all integers for odd $$$n$$$ and halfintegers for even $$$n$$$ from range $$$[\text{median}(A_1, \ldots, A_n), \text{median}(B_1, \ldots, B_n)]$$$.

    To prove we can't reach any other value we only need to see, that median of an integer sequence is an integer for odd $$$n$$$ and a half integer for even $$$n$$$ and see that we can't reach a value outside that segment, but this is straightforward conclusion from the fact, that if all values increase or stay the same, then the median can only increase or stay the same as well.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

If anyone is still stuck at D here is a Solution

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I am Facing problems in the C . No matter what I submit , I am shown wrong answer in 6/22 cases . I am not understanding where is the error or fault exists in that code .. If anyone knows , please give me the solution . My code is given below ::::

include<stdio.h>

int main() { long long int a,pro1; double b,pro=1.0; scanf("%lld %lf",&a,&b); b=b*100; pro=(a*b); pro1=(long long int)(pro/100); printf("%lld",pro1); return 0; }

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    For big values of $$$a$$$ the variable $$$pro$$$ has simply not enough bits to store the exact result of $$$a*b$$$. In this case the double type truncates bits, which results in pro1 beeing some other value than the mathematecally expected one.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone help me where I'm going wrong in problem D, I'm getting hand_22 as the only test case as WA. Here is my code https://atcoder.jp/contests/abc169/submissions/14102528 Thanks