Common BoardWhat answer in this case? "Output any of the most powerful spells..." Any of them. Нужно убрать максимальное количество ребёр, но чтобы все вершины имели ненулевую степень. I thought that stack is the best thing in this case but I've seen 0.015 and 0.001 sec . I've got 0.046 Maybe it's because of the choice of language. I use C++17 and it run in 0.001s First method: Use multiple baskets, each basket is a list (in my case, i use vector<int>). Put the date d into the basket numbered d % number_of_baskets. To check the student answer, just pick the basket out and perform binary search. I chose 100 000 as the number of baskets, tried 1 000 000 baskets but it works much worse. Second method: Use vector<bool> (not bool array, the later cost 8 times more) to mark numbers under 300 000 000 (actually the vector size can go up to 500 000 000, but for some unknown reason, this smaller size run faster). Create another vector<int> to store the numbers that can't be marked using the bool vector above. Use binary_search to check for existence. It seem like the IO is bottleneck, I used ios::sync_with_stdio(false) and my program run from ~1.5s to ~0.2s Edited by author 01.10.2018 12:46 seems I have solved memory problem.. but I don't know if bitset can fit in time can O(1e8) fit into 1 sec?? Edited by author 27.09.2018 06:21 memory can be done O(n*sqrt(n)/64) finally I came up with N*LG(N) sol, I nearly spent 4 days on this problem... I think I can optimize it to O(n) suffix array can bedone by sa_is Edited by author 30.09.2018 09:13 Hey, I've been spending some time thinking over this problem and I'm really stuck on how to make it work fast enough. I was wondering if you could point me in the direction I should be looking to solve it. What I did first was to write a simple bruteforcer and to just verify that that works. It is of course way to slow to get the answer as the input size grows. My next idea was to create a graph out of the possible solutions and this seems promising, but just the time spent building the graph seems to be to much in itself to get a pass, not to speak of the memory requirements. Right now I've been looking into suffix trees, but I don't really know how they would help me here, it's just the closest data structure to the problem that I could find. I really want to solve this on my own, but right now I don't know what topics to research. Could you give me a hint in what direction I should be looking? My sol involves suffix array and some count tricks. first of all we initialization [i,n-1] [0,i] is losing state, and the substring with same oddity is losing state a different is winning state and count winning state +1 (it is a segment you can use fenwick tree to doit) then we consider to enum the length of longest common substring, and merge the substring with longest common length of this length,if one of them is winning states ,then all of them are winning states. how to merge them: using disjoint set, and how to find winning states we can record substring [x,y] pref[x+y],win[x+y] as previous substring [l,r] with l+r==x+y and find this wining state by differece of odditiy of current substring and pref[x+y]. when merging them delete the node if it is not the root node, (i.e. do it count minus one count the all segments [l,r] l-x==y-r with same oddity if it is win,different if it is lose. fenwick array can do it) and change the count when root node's winning states is update.. btw in fact we can throwout fenwick just using ordinary array and count sum of prefix of the array as number of its winning states. I have heard there is O(N) rmq so this problem can be done in O(n) btw there are many details on implement in my sol so I have spent nearly one week on this problem. maybe there are better sols... Edited by author 30.09.2018 13:46 Edited by author 30.09.2018 14:01 Hi! I'm the author of the problem, feel free to discuss solution with me in hangouts: adamant.pwn@gmail.com, or (preferrably) telegram: @adamant_pwn. If you want to :) If you got WA, especially if you got WA9 First line is input string, second is answer TEST. TEST? TEST! TEST. Test. Test? Test! Test. ?????????????????????? ?????????????????????? !TEST!TEST! !Test!Test! A A TEST TEST TEST Test test test TEST T TEST Test t test Also try empty input. Edited by author 30.09.2018 19:14 This enchanted test 8: I just can not get through it. Maybe there is just that unrepresentable case of "impossible", the emergence of which, under given conditions, I can not even imagine? I have a feeling that there is still some condition that the author forgot to mention. Most likely, this is the upper limit for the result. Edited by author 29.09.2018 22:19 I dont understand: when I had swaped 'Impossible' to '0' my program solved more tests than late. there is no test where the answer is impossible, you can can make every mark you want Even below 1.0 or above 10.0? I also do not see under what conditions it can be "impossible". Even if y = 1.0, then this is the result of rounding, but the ratio of the sum of estimates to their number, equal to 1.0499, really approaches. void fallBack(int angle, int M, int curEnergy, int curAmmo); void advance(int angle, int M, int curEnergy, int curAmmo); int findX(int curEnergy); int main() { int curEnergy, curAmmo; char behaviour; int M, MP, angle; int N, NP, offset; scanf_s("%i %i", &curEnergy, &curAmmo); scanf_s(" %c", &behaviour); scanf_s("%i %i %i", &M, &MP, &angle); if (behaviour == 'A') { scanf_s("%i %i", &N, &NP); } else if (behaviour == 'P') { scanf_s("%i", &offset); offset *= -1; } while (1) { switch (behaviour) { case 'A': if ((N*NP) > (M*MP * 3)) { advance(angle, M, curEnergy, curAmmo); return 0; } else { fallBack(angle, M, curEnergy, curAmmo); return 0; } case 'D': if ((M * 20) >= curAmmo) { fallBack(angle, M, curEnergy, curAmmo); return 0; } else { behaviour = 'G'; break; } case 'G': if (M == 0) { printf("STOP"); } if (abs(angle) < 5) { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); return 0; } else if (angle >= 5) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (angle <= -5) {
printf("RIGHT %i", findX(curEnergy)); return 0; } case 'P': if (M != 0) { behaviour = 'D'; break; } else { if (offset >= -180 && offset <= -160) { printf("BACKWARD %i", findX(curEnergy)); return 0; } else if (offset > -160 && offset < -90) { printf("RIGHT %i", findX(curEnergy)); return 0; } else if (offset >= -90 && offset < -20) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (offset >= -20 && offset <= 20) { printf("FRONT %i", findX(curEnergy)); return 0; } else if (offset > 20 && offset <= 90) { printf("RIGHT %i", findX(curEnergy)); return 0; } else if (offset > 90 && offset < 160) { printf("LEFT %i", findX(curEnergy)); return 0; } else if (offset >= 160 && offset <= 180) { printf("BACKWARD %i", findX(curEnergy)); return 0; } } } } return 0; } void fallBack(int angle, int M, int curEnergy, int curAmmo) { if (abs(angle) >= 5 || M == 0) { printf("BACKWARD %i", findX(curEnergy)); } else { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); } } void advance(int angle, int M, int curEnergy, int curAmmo) { if (abs(angle) >= 10 || M == 0) { printf("FRONT %i", findX(curEnergy)); } else { int P = (int)fmin(20, curAmmo); printf("FIRE %i", P); } } int findX(int curEnergy) { int X; if (curEnergy > 100) { X = 100; } else { X = curEnergy; } return X; } Event simple A+B get's around 900KB for me, but I've seen some ACs with 400KB in Java 1.8. Can you tell me how? is it doing search in O(1) for each pair of nodes? Write code that way: if(n>=1000) puts("legion"); else if (n>=500) puts("zounds"); else if (n>=250) puts("swarm"); else if (n>=100) puts("throng"); else if (n>=50) puts("horde"); else if (n>=20) puts("lots"); else if (n>=10) puts("pack"); else if (n>=5) puts("several"); else puts("few"); use printf and scanf instead of cin,cout; Thank you! Very useful hint with cin,cout my programm get TLE on test 21 Or use cin.sync_with_stdio(false); sync doesn't help. scanf_s/printf got me through time limit. PS unordered_map gives little speed boost too. Edited by author 11.06.2014 12:31 ios_base::sync_with_stdio(false); cin.tie(0); with map 0.249s.with unorderd_map 0.171s. a=[] for i in range(int(input())): c=str(input()) if len(a)==0 : a.append(c) continue d=(a[0].split())[1] d=int(d) k=int((c.split())[1]) if k>=d : a.reverse() a.append(c) a.reverse() else: for j in range (len(a)): h=int((a[j].split())[1]) if k >= h: p = a[:j] o = a[j:] p.append(c) p.extend(o) for i in range(len(a)): print(a[i]) Edited by author 26.09.2018 20:38 the number of integer point inside circle is sigma(r*r/(4*i+1)-r*r/(4*i+3)) use stern borcot to cut hyperbola curve it can be done O(r^(2/3)) what do you mean by cut huperbola curve? maybe we can directly use stern borcot tree to cut circle I think it is faster... basic idea is use line segment (x1,y1) --->(x2,y2) with slope -a/b(a>0,b>0) to cut quadric curve so that all of integer point strictly under this line segment is inside the quadric curve (x1,y1) and (x2,y2) is strictly outside the curve if we know (x1,y1),(x2,y2) and -a/b we can find next -(a1/b1) a/b and a1/b1 is neibour in stern borcot tree .it can be proved there are O(n^1/3) state if the quadric curve is huperbola curve x*y==n My solution convert this problem to compute simga(r*r/(4*i+1)-r*r/(4*i+3)) so it is huperbola curve (4*x+1)*y==r*r and (4*x+3)*y==r*r I have done twice ,so it is slow, dirctly cut circle only do once... Edited by author 25.09.2018 21:34 Edited by author 25.09.2018 21:37 will try that for sure, I don't see any way I can speed up my current solutoin, I only need to calculate squares n-(n/sqrt(2)) times, and I do only +/- operations per iteration(no sqrt and multiplication/divisions). and for any n, it runs 0.75-0.8 sec on my pc, but I still get TLE18 here. your computer is too strong, ural oj O(1e9) can't fit into 2 sec Edited by author 26.09.2018 20:03 int main() { optimize(); int n,k; cin>>n>>k; k--; int z=k; bool b=0; int a[n+10]; for(int i=0;i<n;i++) { if(k!=0) { if(b==0) { a[i]=k; b=1; z--; } else { if(z==0) { a[i]=0; k=0; b=1; continue; } a[i]=-k; k--; b=0; z--; if(z==0) k=0; } } else a[i]=0; //dbg(z); } for(int i=n-1;i>=0;i--) cout<<a[i]<<" "; //return main(); } when going to print 0 0 -3 3 or -3 3 0 0 I am getting WA..But When I print 0 0 -1 1 I get AC..Why?what is the difference between 1st two case and last one??Can anyone explain me?? Thanks to Oleksandr Kulkov for preparing! Thanks I almost have no problem to do on ural |
|