Common BoardWhat is algorithm? What formulas, theorems, equations and hints must I use? Any hints? =) Minkowski addition. Thx Really, if we can find A-B then we must understand that [0,0] belong to A-B or not If 'yes' then answer = max{0, dist([0,0], A-B) - 60} If 'no' then answer = 0 My code is as following: #include<iostream> #include<vector> using namespace std; long getMaxSumRow(long rowArr[], int n) { long cs = 0; long ms = 0; bool positiveNumberPresent = false; for (int i = 0; i < n; i++) { if (!positiveNumberPresent && (rowArr[i] >= 0)) { positiveNumberPresent = true; } cs += rowArr[i]; if (cs < 0) { cs = 0; continue; } if (cs > ms) { ms = cs; } } if (positiveNumberPresent) { return ms; } ms = rowArr[0]; for (int i = 0; i < n; i++) { if (rowArr[i] > ms) { ms = rowArr[i]; } } return ms; } long maxSumRec(vector<vector<long> > &arr, int n) { if (n == 1) { return arr[0][0]; } /* Take an array for running rows sum */ long runningRowSum[n]; for (int r = 0; r < n; r++) { runningRowSum[r] = 0; } long maxSum = INT_MIN; /* Initialize variables for left-right and top-bottom bounds */ int left, right, top = 0, bottom = n-1; /* Iterate from all possible lefts to all possibe rights ahead of this left */ for (left = 0; left < n; left++) { for (right = 0; right < n; right++) { for (top = 0; top <= bottom; top++) { runningRowSum[top] += arr[top][right]; } /* For this left-right combination, calculate contigeous subarray with maximum sum in runningRowSum */ long currSum = getMaxSumRow(runningRowSum, n); if (currSum > maxSum) { maxSum = currSum; } } /* Reinitialize running row sum to 0 */ for (int r = 0; r < n; r++) { runningRowSum[r] = 0; } } return maxSum; } int main() { int n; cin >> n; vector<vector<long> > arr(n); for (int i = 0; i < n; i++) { arr[i] = vector<long>(n); for (int j = 0; j < n; j++) { cin >> arr[i][j]; } } cout << maxSumRec(arr, n); return 0; } But I am getting wrong answer for test case#3 . Any advice on what it might be failing at ? 3 4 1 2 1 3 4 5 4 6 ans: 1 5 6 2 3 4 Edited by author 03.09.2019 09:23 There cannot be any impossible case as is suggested by the very first line of the problem statement yes , no impossible cases are present. My Endlish is not that good, could anyone translate it into Russian, pls? Так с гугл-переводчиком понятно inputs of the third test? and in the 4 try this: 3 5 9 aa aa aaa aa aa aa aaa aa aaa i have passed the test you give, but i still got WA3....help //i found a silly mistake and now passed test3... but still WA for the next Edited by author 26.03.2012 11:13 Edited by author 26.03.2012 11:14 //i found a mistake again.....and then i got AC Edited by author 26.03.2012 11:20 What was your second mistake? answer: 3 для первого теста для второго 2 Edited by author 21.10.2012 12:43 You can try this test case: 3 2 6 aa a a aa aa a Correct answer: 2 Isn't corect answer 6? aa a a (not a a = 3 symbols) aa aa a Thanks Deleted Edited by author 24.08.2019 23:00 Try this test: 1 5 2 to be answer: 1 Edited by author 25.09.2015 16:26 Try this test inp 901000 ans 910000 And this input: 091 output: 109 and 092 119 0920 1019 Edited by author 22.12.2006 19:08 My program "give AC" on your tests, but give WA#19. Somebody, give me more tests please. Try this 39910000 -> 40000099 99 -> -1 00 -> -1 1 -> -1 011 -> 020 Good Luck!) Edited by author 06.06.2009 23:08 Edited by author 06.06.2009 23:08 Try this and look for the time 010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Should give 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Edited by author 18.07.2007 05:06 My program give AC on your tests, but give WA#4. Please give me tests #4 or more tests. Thank. Test 59 look like: 1000000000000000000000000 Answer: -1 I run out of ideas, trying to pass test #5. Does anyone can tell me how this test looks like? Thank you, There seem to be some non-ASCII characters in the test cases. If the input is loaded byte by byte, then the result should be output byte by byte as well. I used Rust and handled the bytes as chars, which were stored as 4-byte unicode, but mistakenly output the result by chars instead of bytes. Good test: 16 0 0 3 0 3 1 4 1 4 0 7 0 7 2 6 2 6 1 5 1 5 2 2 2 2 1 1 1 1 2 0 2 My AC program prints 7.000000 Another test: 13 1 1 3 1 3 3 5 3 5 5 3 5 4 4 2 4 2 2 1 3 0 3 0 0 1 0 Answer: 7.071068 If your program has O(n^2*log(n)) time complexity or faster try the following tests: 10 4 10 0 0 5 0 5 3 13 3 10 8 5 8 7 5 2 1 5 10 Answer: 12.276044 24 13 10 11 17 7 20 1 20 1 11 13 0 23 7 23 19 14 22 20 18 18 11 13 6 5 15 13 4 20 8 13 3 8 7 3 14 3 17 6 17 13 8 17 17 11 20 14 17 Answer: 20.645581 29 17 13 11 12 10 10 12 6 22 6 23 13 12 18 0 14 12 1 14 2 7 12 12 15 20 13 18 10 12 10 19 8 21 13 12 16 5 13 12 3 2 14 12 17 22 13 21 7 12 7 11 10 19 13 13 14 10 13 Answer: 18.193976 Edited by author 25.08.2019 17:28 Is it really needed to set 4mb memory limit? I really must to remember pascal for this task, because the same solution have TL (not a Scanner) or ML on java. May be it's possible to up memory limit to 8mb? #include<bits/stdc++.h> using namespace std; const long long size=65535; long long ara[size]; long long b[size]; Find() { long long i, sum=1, j; for(i=0, j=1; i<=size; i++, j++) { sum=sum+i; ara[j]=sum; } } int main() { long long i, n, a, r, j; Find(); cin>>a; for(i=1; i<=a; i++) { cin>>b[i]; } for(i=1; i<=a; i++) { r=0; for(j=1; j<=size; j++) { if(b[i]==ara[j]) { r=1; break; } } if(r==1) { printf("1 "); } else { printf("0 "); } } printf("\n"); return 0; } Code removed Edited by author 20.08.2019 21:12 8*n-7 <--- integer overflow Integer overflow. But why? And How? Edited by author 17.08.2019 19:12 [code deleted] This code gets wrong answer in case #3. Edited by author 18.08.2019 20:49 Edited by author 18.08.2019 20:49 Edited by moderator 17.11.2019 18:48 On timus 'long int' is equal to 'int', to use 64-bit integers you need to write 'long long'. Also, there is a precision error in your 'per_sq' function. This line: return ((x-floor(x))?0:1); must be written as return (abs(x-floor(x)) > 1e-8 ? 0 : 1); Thanks. I didn't know about the bit size of long in Timus. And what you said about the function. I had problem in the argument. I used double instead of int then it got accepted. I can't understand how to solve the problem with Python and meet time limitations. I implemented solution with creating 3-D list of subsumes[column][row_start][row_offset] using accumulate from itertools and list comprehension. After that I used Kadane's algorithm. I expect that it works with O(N^3). But it isn't enough... Are there some tricks in the problem for Python? Except for stdin of course. t = int(input()) for i in range(t): m = [] kv = 0 n,k = map(int,input().split()) ok =k for i in range (k): if i == 0: m.append(n//ok) kv += m[i] n-=n//ok ok-=1 else: if i == k-1: m.append(n) else: m.append(n//ok) kv+=m[i] n-=n//ok ok-=1 otr,ans = 0,0 l,l1 = 0,0 m.sort() m.reverse() ss = sum(m) for i in range(k-1): l += m[i] l1 = m[i] ans += (ss-l)*l1 print(ans) t = int(input()) for i in range(t): n, k = [int(i) for i in input().split()] m = n // k q = n % k s = (m * (n - m) * (k - q) + (m + 1) * (n - m - 1) * q) // 2 print(s) #распределяем максимально равномерно и "деремся" команда из m против всех оставшихся + команда из m + 1 против всех оставшихся и, поскольку учли каждый бой по два раза (для обоих участников), делим пополам =) my code passed yours test but shows WA1 #include <bits/stdc++.h> using namespace std; int main() { int N,a[55],b[55],i,c[55],j,d[55],t,e[55],m,n; unsigned long long x,y,p,arr[55]; cin>>N; for(i=0;i<N;i++){ cin>>a[i]>>b[i]>>c[i]>>d[i]; e[i]=i; } cin>>m>>n; for(i=0;i<N;i++){ x=max(a[i]-m,m-c[i]); if(x<0){ x=0; } y=max(b[i]-n,n-d[i]); if(y<0){ y=0; } arr[i]=x*x+y*y; } for(i=0;i<N;i++){ for(j=i+1;j<N;j++){ if(arr[i]>a[j]){ p=arr[i]; arr[i]=arr[j]; arr[j]=p; t=e[i]; e[i]=e[j]; e[j]=t; } } } for(i=0;i<N;i++){ cout<<e[i]+1<<" "; } return 0; } /****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; int main() { int N,a[55],b[55],i,c[55],j,d[55],e[55],m,n; unsigned long long x,y,arr[55]; cin>>N; for(i=0;i<N;i++){ cin>>a[i]>>b[i]>>c[i]>>d[i]; e[i]=i; } cin>>m>>n; for(i=0;i<N;i++){ x=max(a[i]-m,m-c[i]); if(x<0){ x=0; } y=max(b[i]-n,n-d[i]); if(y<0){ y=0; } arr[i]=x*x+y*y; } for(i=0;i<N;i++){ for(j=i+1;j<N;j++){ if(arr[i]>a[j]){ arr[i]=arr[j]; e[i]=e[j]; } } } for(i=0;i<N;i++){ cout<<e[i]+1<<endl; } return 0; } #include<stdio.h> int main(){ int N, n, k, i, a, b, x, res; scanf("%d\n", &N); for(i=0; i<N; i++){ scanf("%d %d", &n, &k); if(n%k==0){ x=n/k; res=n*(n-x)/2; printf("%d\n", res); } else { x=n/k; b=n-k*x; a=k-b; res=((n-x)*a*x+(n-x-1)*(x+1)*b)/2; printf("%d\n", res); } } return 0; } #include <bits/stdc++.h> string c[4] = {"88", "68", "06", "16"}; int main() { cin >> n; if (n > 4) { cout << "Glupenky Pierre" << endl; return 0; } for (int i = n - 1; i >= 0; i--) cout << c[i] << " "; } "68 88" is good, isn't? There are many more combinations. You also forgot 9 n, m = map(int,input().split(' ')) voices = [] p = ['p'] h = 0 for i in range(m): voices.append(int(input()))
for i in range(n): p.append(0) for i in voices: for c in range(n+1): if i == c: p[c] += 1
for i in range(1, len(p)): h = p[i] / m * 100 p[i] = str(round(h, 2)) if len(p[i]) == 4: p[i] += '0' print(p[i] + '%') Help. what's wrong n, m = map(int,input().split(' ')) voices = [] p = ['p'] h = 0 for i in range(m): voices.append(int(input())) for i in range(n): p.append(0) for i in voices: for c in range(n+1): if i == c: p[c] += 1 for i in range(1, len(p)): h = p[i] / m * 100 print(f'{h:.2f}%') This is your code that prints the right answer. Python 3 uses BANKER'S rounding while the problem asks you to the MATHEMATICAL rounding. I used 'f-string' to perform MATHEMATICAL rounding. Anyways, the solution is not fast enough - try to come up with some speed-ups. |
|