Common BoardI failed on 13 test and I can't found error. Please give a 13 test. Edited by author 19.11.2019 23:33 Edited by author 19.11.2019 23:44 We are given positive x and y. Let's go in the first loop. Let's do some method refactoring for better understanding: y0 = x*x+y; x0 = x*x+y0; y1 = sqrt(x0+(y0/labs(y0))*(-labs(y0))); for (j = 1; j <= 2*y1; j++) x0 = x0-y1; x = x0; y = y1; Let's go through the lines: y0 = x*x + y Next: x0 = x*x + y0 = 2*x*x + y As y0 > 0 (x, y are positive) => y0/labs(y0) = 1 So y1 = sqrt(x0+(y0/labs(y0))*(-labs(y0))) = sqrt(x0-labs(y0)) = sqrt(2*x*x + y - (x*x + y)) = sqrt(x*x) = x Next 2 lines equals to this: x0 = x0 - 2*y1*y1 = 2*x*x + y - 2*x*x = y So, x=y and y=x. x and y are swapped. After that you need to count amount of swaps and print appropriate answer Could somebody who solved this problem give some tests to me? WA #7 :( Also asking for some random tests, because it's hard to check the solution. random test: 25 7 3 4.0671982122 good luck =) 100 2 20 0.00000 100 98 1 0.12311156 85 17 53 2.1738219 #include <stdio.h> int main(){ int a,b,c; scanf("%d",&a); scanf("%d",&b); scanf("%d",&c); if (a>b){ if (b>c){ printf("%d",c-(a*b)); } else{ printf("%d",b-(a*c)); } } if(b>a){ if (a<c){ printf("%d",a-(c*b)); } } return 0; } 1) a,b,c sequence is already sorted. 2) Try "1 1 1" input. Answer is -1. I used next_permutation and get AC i used next_permutation and got TLE Hi, I made a countries ranklist here: http://acmtimusru.appspot.com It lists the countries by rating, solved, users or last ac, where: - rating = sum(user.rating) for user in a country - solved = sum(user.solved) for user in a country - users = count of users in a country - last ac = the most recent accepted submission of any user in a country Also, clicking on a country gives you a ranklist of users in that specific country. The ranklists are updated hourly. Enjoy! Edited by author 24.03.2020 14:51That's nice. Thank your for sharing your effort with us! God bless Antarctica! Edited by author 24.03.2020 19:53 Can anybody help Edited by author 20.03.2020 19:35 I don't know why my solution is failing on test case 1, I have tested against all available test cases with correct answer , but cannot pass test case 1, can anybody please tell what is test case 1. Is it possible to change the judge id? Thanks What is test case 1? It's the same as the given sample input. But what if i have the same answer that in sample, and get WA1? import java.util.Scanner; public class javasucc { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int h = 2, s = 10; for(int i=0; i<n; i++) { int a = in.nextInt(); String b = in.next(); if(b=="hungry"){ if(a>h) {h = a;} } else if(b=="satisfied"){ if(a<s) {s = a;} } } if(h >= s) System.out.println("Inconsistent"); else System.out.println(s); } } and the problem is that program doesn't want to do if and i can't change s to a 1) I wasn't crying for help though but just was wondering why 2) Thanks for the link, the problem was actually in "==" n=int(input()) a=[] for i in range(n): s=input() if(s[0]=="A" or s[0]=="P" or s[0]=="O" or s[0]=="R"): a.append(0) elif(s[0]=="B" or s[0]=="M" or s[0]=="S"): a.append(1) else: a.append(2) t=0 for i in range(n): if(i+1<n): t=t+abs(a[i]-a[i+1]) print(t) #include <stdio.h> #include <map> using namespace std; int main() { int ans, sum, ost, s; long int full, i; map <long int, int> sums; for (i = 1; i <= 1000000000; i++) { sum = 0; full = i; do { ost = full % 10; full /= 10; sum += ost; } while (full > 0); sums[i] = sum; } for (s = 1; s <= 81; s++) { ans = 0; for (i = 1; i <= 1000000000; i++) if (sums[i] == s) ans++; printf("{%ld}, ", ans); } } it will give you {10}, {...}, ... , {...}, vector that you can use for getting AC with O(1). Edited by author 11.03.2020 14:40 Edited by author 11.03.2020 14:44 "The numbers are arranged in non-decreasing order (0 ≤ a ≤ b ≤ c ≤ 100)." I my opinion, reading this we assume that the input will already be sorted. #include <iostream> #include <string> using namespace std; int main() { int hun = 2, sat = 10, n; cin >> n; string s; for (int i = 0, num; i < n; i++) { cin >> num >> s; if (s == "hungry") if (num > hun) hun = num; if (s == "satisfied") if (num < sat) sat = num; } if (hun >= sat) cout << "Inconsistent"; else cout << sat; } import java.io.PrintWriter; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Scanner; public class Task_1263 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); String str = in.nextLine(); int candidateCount = Integer.valueOf(str.substring(0, 1)); int votersCount = Integer.valueOf(str.substring(2)); int[] votersForCandidates = new int[candidateCount]; double[] votersPercents = new double[candidateCount]; int voter; for (int i = 0; i < votersCount; i++) { voter = Integer.valueOf(in.nextLine()); votersForCandidates[voter - 1]++; } for (int i = 0; i < candidateCount; i++) { votersPercents[i] = new BigDecimal((double) 100 * votersForCandidates[i] / votersCount).setScale(2, RoundingMode.HALF_UP).doubleValue(); } for (int i = 0; i < candidateCount; i++) { out.printf("%.2f%%%n", votersPercents[i]); } out.flush(); } } Because of the Memory limit: which no more than 64 MB. votersPercents array is useless and should be removed. But the main error is you reading candidateCount in the wrong way. str.substring(0, 1) - how many digits can you read? What max candidateCount is? You use Scanner class. It has method nextInt() - you can just use it, you don't need to read strings and split them into numbers manually. 42 8 2 4 6 13 14 14 19 26 26 30 60 89 89 89 89 90 90 90 90 90 91 91 93 94 94 94 94 94 94 94 95 95 95 96 96 97 98 98 98 99 100 100 184 186 209 402 408 488 621 622 Are you sure? It get 0 nanoseconds for mine TLE67 version (for any random permutation of input). Edited by author 06.03.2020 00:50 Yes, I am sure. The tests are a bit peculiar for this problem. Some group of tests target specific solutions, so it's entirely possible your solution deals with some of the last tests easily (there should be 81 of them), but fails on earlier ones. Edited by author 05.03.2020 18:15 Thank you for the information. |
|