Common BoardIs 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. $ Before going to the solution, make sure that you had tried enough, please. $ Code:- #include<bits/stdc++.h> #define START int main(){ #define END system("PAUSE");return 0;} using namespace std; START int n, guest=2; cin >> n; guest += n; while(n--) { string s; cin >> s; for(int i=0; i<s.size(); i++) { if(s[i]=='+') { guest++; } } } if(guest != 13) { cout << 100*guest << endl; } else { cout << 100*(guest+1) << endl; } END ///Thank You and Pray for me. Edited by author 05.03.2020 17:01 It's mean you are checking condition if variable N = 45 or N = 5,6,7,8 then go to do statement below your condition N = 45 -> answer = 2269806340 N = 5 -> answer = 10 N = 6 -> answer = 16 N = 7 -> answer = 26 N = 8 -> answer = 42 I've used BST but still cannot optimize it... similar code on C is accepted with 0.171s 300kb but Python is processing the code way longer and TLE #14. And no solutions on python so far. Is there something that can be done? The minimal output is: 1-2*5 = -9. Edited by author 04.03.2020 22:45 consider follow string: ABZZBBBZZA. 2 polindroms: ZZBBBZZ and ABA - correctly for this problem? i think answer is 3 polindroms: AB ZZBBBZZ A I thin its 4 palindromes A B ZZBBBZZ A Смотрю с любовью на свои более 10-летней давности попытки решать задачи. Спасибо, ACM.Timus! Python 3.6 a=int(input()) if a<=4 and a>=1: print("few") if a<=9 and A>=5: print("several") if a<=19 and a>=10: print("pack") if a<=49 and a>=20: print("lots") if a<=99 and a>=50: print("horde") if a<=249 and a>=100: print("throng") if a<=499 and a>=250: print("swarm") if a<=999 and a>=500: print("zounds") if a>=1000: print("legion") Попробуй другие отступы num_monst = int (input ("Write number of monster")) if 1 <= num_monst <= 4: print("few") elif 5 <= num_monst <= 9: print("several") elif 10 <= num_monst <= 19 : print("lots")
elif 20 <= num_monst <= 49 : print("horde") elif 50 <= num_monst <= 99 : print("throng") elif 100 <= num_monst <= 249 : print("swarm") elif 250 <= num_monst <= 999 : print("zounds") elif num_monst >= 1000 : print("legion") Ya popitalsya perebrat' vse varianti dlya N = 6 i smog naschitat' tolko 14 vot oni: 1. WRWRWR 9. WRWRBW 2. RWRWRW 10. RWRWBR 3. WBRWRW 11. WBRBWR 4. RBWRWR 12. RBWBRW 5. WRBWRW 13. WRBWBR 6. RWBRWR 14. RWBRBW 7. WRWBRW 15. ?????? 8. RWRBWR 16. ?????? Kakie dva ya upustil? #include<stdio.h> int n,k,answer; int main() { scanf("%d %d",&n,&k); int len = n/2; if(k==len) { printf("0"); return 0; } else if(k<len) { answer = len - k; } else { answer = k - len - 1; } printf("%d",answer); } I have the same problem: test no. 5, wrong answer. (Sorry, i don't know english well) Я запихнул свой алгоритм в циклы for, ввод всех возможных значений, вывод. Просмотрел всё вручную, нет ошибок! Carefully read the condition. Visitor chooses a side in such a way that the number of people over whose feet he will stumble will be minimal. It is not always the shortest path. Внимательнее читайте условие. Зритель выбирает сторону так, чтобы споткнуться о меньшее число людей. Это не всегда наикратчайший путь. Try test 50 50 answer 47 40-20 18 40 27 24 .... ???? PROFIT!!! Edited by author 08.06.2010 03:26 Edited by author 08.06.2010 03:27 k == n is the same situation as k == 1 3 1 2 10 2 3 100 3 4 1000 1 1 2 10 Answer: 2 2 3 100 3 4 1000 #include <bits/stdc++.h> int main() { int n,i,j,k; scanf("%d",&n); for(i=1; i<=n; i++){ if(i==1 && n!=1){ printf("("); } for(j=1; j<=i; j++){ if(i==1 && n==i){ printf("(sin(1))+%d",n); } else if(i==1){ printf("(sin(1)+%d)",n); } else { if(j%2==0){ printf("-sin(%d",j); } else if(j==1){ printf("sin(%d",j); } else { printf("+sin(%d",j); } if(j==i){ //printf(")"); for(k=1; k<=i; k++){ printf(")"); } } } } //if(i==n){ // printf(")"); // } if(i!=1 && i!=n){ printf("+%d)",n+1-i); } else if(i!=1 && i==n){ printf("+%d",n+1-i); } } return 0; } My algorythm has maximum O(n^2) complexity. I have TLE 18 test. But, when i artificially set limits for n (amount of layers) to 200 and for k (amount of bricks in a single layer) to 290, my program still gets TLE 18 test, i really have no idea how is it possible. It should get WA\AC if inputs are more than limits since i do not see any possibility of an endless cycle in my algo. Edited by author 27.02.2020 21:19 Edited by author 27.02.2020 21:36 |
|