Общий форум Edited by author 09.05.2025 09:16 It was due to overflow. I changed a few variables to long long and it got accepted. Edited by author 25.08.2015 13:20 Edited by author 25.08.2015 13:20 Please give some additional info "Nikolay thinks an integer is interesting if it is a prime number. However, Asya thinks an integer is interesting if the amount of its positive divisors is a prime number " If it so, "Nikolay and Asya are happy when their tastes about some integer are common." How come it can be true, prime number is a number which does not have divisors except for 1 and itself, but it says ,in Asya sentence, that "amount of its positive divisors is a prime number ",Does it mean 1 and the number given ? Can somebody explain it to me and the sample given below the problem , please It means that all numbers, which are interesting to Nikolay, are also interesting to Asya, but there are some numbers, which are interested to Asya only. For example, in first sample: 3,5,6,7 are interested to both, 4 is interested only to Asya. And yes, surely divisors of some number include 1 and this number. Edited by author 06.08.2016 21:02 How can the number 6 be of interest to Nicholas if it is not prime? The problem can be reduced to a matching problem. It can be solved by Dinic's algorithm. what in test #5? Numbers of Haters can be placed in non-ascending order. After I started checking "1" not only at first position, I got AC what about ternary search in this task? Edited by author 01.10.2020 22:01 Well I tried to do so but got wa4. I also looked at that guy's solution where he just takes the average of all p[i]. And I still cannot understand why it's right bcz, like, it's squared distance not just linear... Edited by author 29.07.2022 12:21 It's because of the first derivative. I tried it, and get WA4. I suspect I have a bug but idk where. I did some more digging. For those interested, try running your ternary search against the following test case (and then compare with the avg approach): ``` 20 9 8 5 12 5 6 89 45205 3554 1585 554422 654235 545324 548835 456432 804654 234758 444 5668 56435 ``` This in both cpp and python gives the wrong answer. By switching to the `Decimal` library in python, I was able to move past 4, and get TLE on 5. Using gmp in cpp might get you to AC, but I think the takeaway here is to only use ternary search when you can set the problem up to have an answer close to 0. please consider very small cases First i tried to solve this problem using int64 (long long) , i got WA6. Then i used long number theory to solve this problem and i got AC!) Good luck! what's that "long number theory" ? i think we need to switch to python. Yeah! Just use Python and it will be accepted! I think it's time to start to learn Java, just some simple things(like input and output) and BigInt. It could probably help me in those long arithmetics case. Problem can be reduced to edges in complete graph: Given no. of edges, what is the max no. of vertices in a complete graph? del Edited by author 20.02.2024 17:47 Я просто накидал кучу каких-то непонятных оптимизаций, и оно почему-то зашло //please tell me what's wrong, cause i cant understand... #include <bits/stdc++.h> #include<fstream> #define all(a) (a).begin(), (a).end() #define ll long long #define sz size #define dbl double #define vll vector <ll> #define INF LLONG_MAX #define uniq(x) x.resize(unique(begin(x),end(x))-begin(x)) #define forik(i,m,n) for(ll i=m;i<n;++i) #define re return using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(); vll numbers; ll num; while (cin >> num) { numbers.push_back(num); } for (ll i = numbers.size() - 1; i >= 0; i--) { dbl nek = sqrt(numbers[i]); cout << fixed << setprecision(4) << nek << endl; } re 0; } #include <iostream> #include <stack> #include <cmath> using namespace std; int main() { stack<double> root; double input;
while(cin >> input) { root.push(sqrt(input)); }
while(!root.empty()) { cout << root.top() << endl; root.pop(); }
return 0; } Here your first input while is going infinnity. You have to stop it. 435 981 301 -384 -1 345 0 Correct answer: 371.78 789.08 thanks for the test found a mistake ( ˘ ³˘)♥︎ My solution produces an automaton with 2n^2 + n states, but what is the smallest possible size? Is it still ~n^2? Edited by author 14.02.2024 16:19 worked at least two months.... I think it is a hard problem,harder than some rating>1e4 problems... How did you get the skill to solve such a hard problems? I know generic patterns to effective skill training Interested in particular case Edited by author 08.11.2017 21:17 Just stop solving easy problems,and trying harder one.. I start solving hard problems since year 2010 practicing at http://poj.org solving AC<100 problems and at year 2013 I start solving topcoder Div I 1000pts.. later I found codeforces and start solve fewest AC problems.. There are also some Chinese oj hardest problems is very hard such like http://www.lydsy.com/JudgeOnline/ http://uoj.ac/ Yeah, solving hard is very helpful, I felt it At some point I noticed that I am just not able to solve some harder problem Because it takes very much time to solve So even if trying whole day then cannot solve Maybe whole week is enough But very rarely have an opportunity to solve a problem the whole week Typical have only three hours per day But it's at cost of sacrificing important things So I feel like I cannot improve further Yeah, solving hard is very helpful, I felt it At some point I noticed that I am just not able to solve some harder problem Because it takes very much time to solve So even if trying whole day then cannot solve Maybe whole week is enough But very rarely have an opportunity to solve a problem the whole week Typical have only three hours per day But it's at cost of sacrificing important things So I feel like I cannot improve further you can choose some easier than hardest problems but harder than medium problems if you don't have enough time to practice On spoj.com I have lot of tasks in my TODO list... Why do you consider it a hard problem? It felt quite straightforward to me Timus has very few constructive problems (at least with difficulty >= 2000), so this problem may seem hard compared to others if constructive problems are not your strong point Bruteforce all short numbers (i. e. length <= 3) and feed them to both input and output automata, then compare. Here are some useful tests: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 0 1 0 1 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 8 3 0 1 0 1 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 These tests didn't help me figure out the issue, but maybe they can be useful for community 7 0 0 0 2 1 1 1 3 3 1 0 -1 -1 0 3.95284707521047407042 6 0 1 1 2 0 2 -1 1 -1 0 1 0 2.82842712474619029095 7 2 0 2 3 -2 3 -2 0 -2 -2 0 -2 2 -2 6.40312423743284853117 3 0 0 1 0 0 1 1.41421356237309514547 8 1 2 1 3 2 2 2 1 1 0 1 1 0 1 0 2 3.00000000000000000000 12 2 0 1 1 0 1 1 0 0 -2 -1 1 -1 2 0 2 -1 3 -4 0 0 -4 0 -1 6.79869268479037932229 12 2 0 1 1 0 1 1 0 -2 0 -1 1 -1 2 0 2 -1 3 -4 0 -3 -1 0 -1 6.00000000000000000000 7 0 0 1 2 1 1 3 1 1 -1 1 -3 -1 0 5.00000000000000000000 16 3 0 4 1 3 1 3 2 2 2 2 1 1 1 1 2 0 2 0 1 -1 1 -1 2 -2 2 -2 1 -3 1 -2 0 7.00000000000000000000 1. Use scanf/printf instead of cin/cout 2. Use make_heap, push_heap and pop_heap instead of priority_queue 3. Use C-style array instead of vector 4. Do not allocate n elements for an array |
|