Общий форумProblem statement says "His friends write numbers from 1 to N on cards", but it doesn't mention that these numbers should be distinct. Yet, it seems like the problem only accepts solutions in which the numbers are distinct (i.e. the numbers on the N cards are a permutation of [1..N]). Since you're able to download it, you can actually decompile it and submit the code to get accepted. There's a Thread.Sleep(3000) in there that you'll need to comment out. The cases when all times are less than 6 seconds are neglected. So the cost of each plan should be zero as all calling will be free but adding the basic plan to the cost leads to AC. puts gets.split(' ').sum { |s| s.to_i } а вот так ок: puts gets.split(' ').map { |s| s.to_i }.inject(0) {|sum,x| sum + x } что не так с с sum? Edited by author 22.05.2019 11:43 Edited by author 29.05.2019 02:44 Any hints for solution? I am completely stuck at TLE. So, we can decompose like this any connected graph G = (V, E), |E| = 2k, k in Z+? This is lovely, this is nice (I proved it using induction, I'm proud of myself, yay!). I came up to this idea, but failed to proof. It is easy to solve this problem by using such recursive formula (k+1)P_k(N)=(N+1)^(k+1)-1-sum_(l=0)^(k-1) C_(k+1)^l P_l(N), where P_k(N) is a sum of powers k from 1 up to N, C_k^l is a binomial coefficient. I assume that P_0(N)=N. You can check this formula by summing up from 1 to N following identities (n+1)^k-n^k=sum_(l=0)^(k-1) C_k^l n^l. However, P_k(x) has non-integer coefficients, so it is better to introduce polynomials Q_k(x) by formula Q_k(x)=(k+1)!P_k(x). It can be proven by induction based on recursive formula above that Q(x) has integer coefficients!!! So, use BigIntegers in Java, otherwise you would have overflow. Good luck! Edited by author 08.05.2017 19:44 Edited by author 08.05.2017 19:44 You can make a system of linear equations with k+2 variables and equations, which would look like: A_0 * 1^0 + A_1 * 1^1 + ... + A_(k+2) * 1^(k+2) = 1^k A_0 * 2^0 + A_1 * 2^1 + ... + A_(k+2) * 2^(k+2) = 2^k ... A_0 * (k+2)^0 + A_1 * (k+2)^1 + ... + A_(k+2) * (k+2)^(k+2) = (k+2)^k So, you only need to find A_i coefficients using Gaussion elimination. n^3 is suitable for which n<=200 but pay attention to the collinear problem Edited by author 17.05.2019 14:43 #include <stdio.h> int main(){ int n; scanf("%d", &n); if (n == 2) { printf("10"); return 0; } if (n == 4) { printf("670"); return 0; } if (n == 6) { printf("55252"); return 0; } printf("4816030"); return 0; } Here is nothing interesting! It's cheating solution. You precalc all variants and nothing else. I don't think, that this solution is cheating, but it also isn't interesting. Just a simple problem.) It is easy to understand why it works but how did you calculate the numbers for 4, 6, 8? With a calculator?!! In Russian this solution call "Частный случай" hmm... [:||||:] "Частный случай" you are right! Every one has a chance to say some thing in mother language...i also saying... এতে ইজি কিছহু নাই। সব ই কথিন। Chinese: 卑鄙啊 oho~I found a partner, Chinese man বুকে আসেন ভাই :D @shahed adnan Edited by author 04.05.2019 21:05 Edited by author 04.05.2019 21:05 This code works but that's not real ans. Edited by author 16.05.2019 12:10 Well he wrote a programm to calculate the answers first, so this is a solution. And due to the performace it is the very good solution. So stop winning and be smart guy. Thanks for giving test data!! \*^_^*/ I thought my solution is quite "brute", are there any other solutions? And I have to say it is a really good problem for sufficient samples and a clear statement. And where is your solution? I cant ivent any tests that my solution will fail, but I have WA1! Can any body help... Give me some test! Plz... example tests 4 0110 0011 0001 1000 4 1 4 2 3 3 2 4 1 my output: No No No No 3 010 000 100 3 1 3 3 1 2 3 out: No Yes No Is it correct? Give some more tests! You should print "YES", but not "Yes"... WA 2 CODE: program china; var t:char; i,j,k:integer; a:array[1..100,1..100] of boolean; b:array[1..100] of integer; chk:array[1..100] of boolean; x,y,q,n,m:integer; procedure solve(k:integer); var i:integer; begin for i:=1 to n do begin if a[k,i] then begin if not chk[i] then begin chk[i]:=true; solve(i); end; end; end; end; begin readln(n); for i:=1 to n do begin for j:=1 to n do begin read(t); if t='0' then a[i,j]:=false else a[i,j]:=true; end; readln; end; for i:=1 to n do begin fillchar(chk,n,false); solve(i); for j:=1 to n do begin if chk[j] then b[i]:=b[i]+1; end; end; readln(q); for i:=1 to q do begin readln(x,y); if b[x]>b[y] then writeln('YES') else writeln('No'); end; end. may be this test will help you: 4 0010 0001 0100 0000 4 1 2 1 4 4 1 4 3 answer: YES YES YES No Why answer for 1 4 and 4 1 YES and what is the anwer for 4 0100 0000 0001 0000 7 1 2 2 1 3 4 4 3 3 1 1 3 3 2 Why answer for 1 4 and 4 1 YES Because you should print "No" only if nodex x and y have common predecessor. In other cases you should print "YES". My answer for your test: YES YES YES YES YES YES YES Thank you, your answer helped me mutch! Because you should print "No" only if nodex x and y have common predecessor. In other cases you should print "YES". Where this is written in the statement? Why can't I solve the problem this way: 1. Make transitive closure of the given graph (matrix A)using Floyd. 2. For every request (pair i j) print "YES" if A[i][j] = 1 otherwise print "No". Because you should print "No" only if nodex x and y have common predecessor. In other cases you should print "YES". Where this is written in the statement? Here: "In this case we say that the team A is stronger than the teams B and C (more formally, A is stronger than B if A has beaten B or if A has beaten a team C which is stronger than B)." Edited by author 18.10.2006 23:11 Edited by author 18.10.2006 23:114 1 anwer is No, because 1 better than 3, 3 better than 2, 2 better than 4 => 1 better than 4 8 AA BB CC DD EE FF GG HH 6 AA HIT BB IN HEAD AA HIT CC IN HEAD AA HIT DD IN HEAD AA REVIVE BB AA REVIVE CC EE REVIVE DD CORRECT AA BB CC FF DD EE GG HH I'll throw in another test for WA 44: 12 A B C D E F G H I J K L 16 A HIT B IN HEAD A REVIVE B B HIT C IN HEAD B REVIVE C D HIT E IN HEAD D REVIVE E E HIT F IN HEAD E REVIVE F G HIT H IN HEAD G REVIVE H H HIT I IN HEAD H REVIVE I J HIT K IN HEAD J REVIVE K K HIT L IN HEAD K REVIVE L FAKE Teams 3+3+3+3=12 cannot assemble into teams of 4. Same, for example, for (3+2)+(3+2)+(3+2)+(3+2)=20, etc. 100000000 10 1 5 even 6 10 even 11 18 even 19 25 even 1 8 even 16 25 even 16 40 even 9 40 odd 1000 5000 odd 1000 6000 odd -1 answer: 7 why is it 7? could you explain? I had runtime error 25, but when i surrounded sorting with try catch it accepted Any ideas why? #solution 1068 x=int(input("enter your number: ")) def factorial(x): if x>0: return x + factorial(x - 1) elif x<0: return x + factorial(x+1) if x==0: return 0 y=factorial(x) if x<0: print(y+1) else: print(y) n = int(input()) if n > 0: print(int(n*(n+1)/2)) elif n == 0: print('1') else: print(int(n*(n-1)/-2 + 1)) delete Edited by author 04.10.2020 16:38 What's wrong with test #38? I got AC with sorting but failed on majority search? I've got AC without sorting. I have failed on #38 recently on a test like: 7 4 1 1 2 1 1 3 |
|