Общий форумSolution in Go. I was getting WA#4 and then changed my input matrix from [][]int8 to [][]int16 and the solution was accepted. Edited by author 21.12.2014 14:38 Who can tell me? Thanks! tests: 4 AAaaaaAA output data: (case 1)2 3 1 4 (case 2)3 2 4 1 (case 3)1 2 3 4 (case 4)4 3 2 1 Which is the correct answer? Edited by author 29.11.2014 18:43 Correct answer for this test is 2 1 4 3 RT @Nodir NAZAROV [TUIT-Karshi] Thanks a lot! AC now! Correct answer for this test is 2 1 4 3 consider line breaks between inputs del Edited by author 06.01.2015 21:37 5 ta satrli 3 ta ustinli listdan nechta kerak. 5 3 6 To be or not to be javob: 2 English please translate: for this testcase correct answer is 2. 5 3 6 To be or not to be del Edited by author 06.01.2015 21:38 THIS IS ACCEPTED CODE // *CoDeD by Ye.A # include <iostream> # include <cstdlib> # include <cstdio> # include <vector> # include <algorithm> using namespace std; const int N = 222; vector <int> g[N], ans; int n; bool used[N]; int main () { //freopen ("input.txt", "r", stdin); //freopen ("output.txt", "w", stdout); scanf ("%d", &n); for (int i = 1; i <= n; i++) while (1) { int x; scanf ("%d", &x); if (!x) break; g[x].push_back (i); }
while (ans.size() != n) for (int i = 1; i <= n; i++) if (!used[i] && g[i].empty()) { ans.push_back (i); used[i] = true; for (int j = 1; j <= n; j++) if (binary_search(g[j].begin(), g[j].end(), i)) g[j].erase (lower_bound(g[j].begin(), g[j].end(), i)); }
for (int i = 0; i < n; i++) printf ("%d ", ans[i]);
return 0; } Here is the code(c++), what is wrong? #include <iostream> #include <string> using namespace std; int main() { string name[1001]; int counter=0; int n,i=0; cin>>n; while(i<=n) { getline(cin,name[i]); if(i!=0) if(name[i-1][0]!=name[i][0]) if(name[i-1][0] == 'A' || name[i-1][0] == 'P'||name[i-1][0] == 'O'||name[i-1][0] == 'R') { if(name[i][0] == 'B' || name[i][0] == 'M'||name[i][0] == 'S') counter++; else counter+=2; } else if(name[i-1][0] == 'B' || name[i-1][0] == 'M'||name[i-1][0] == 'S') { counter++; } else if(name[i-1][0] == 'D' || name[i-1][0] == 'G'||name[i-1][0] == 'J'||name[i-1][0] == 'K'||name[i-1][0] == 'T'||name[i-1][0] == 'W') { if(name[i][0] == 'B' || name[i][0] == 'M'||name[i][0] == 'S') counter++; else counter+=2; } i++; } cout<<counter; } Use a map instead of many "if"s. Can someone give me test cases? I believe my solution works and tried with many possible inputs and I get the right result. I found that it is possible to have more than one input value on the same line. And now I fail to pass #5. Any test cases would be much appreciated. Edited by author 20.12.2014 13:42 import java.io.*; import java.util.*; public class TokenExplain { public static void main(String[] args) throws IOException { //this program gets two tokens on a single line and calculates their sum StreamTokenizer in =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); in.nextToken(); int a=(int)in.nval; in.nextToken(); int b=(int) in.nval; System.out.println(a+b); }
} As you can see, it was well written, but when it was compiled, it took 0.078 seconds while i see fellow java coders clocking speed of 0.031, can you suggesting better classes to read inputs instead of the one i used, all other suggestions are highly welcome It has no problem and can be accepted. Yes, it was accepted but that is not the issue. The real issue is how i can optimize the code in such a way to clock 0.031 sec that others clocked. Thanks. But I cant find the code which clock 0.031 by google. Can anyone help me? deleted: Edited by author 24.12.2014 23:56 What is test 4, there is a question about it but I don't understand the answer. All the eigenvalues are positive integers not exceeding 10^9. Does it mean they are non-zeros? My solution assumes there are not zeros, maybe that's the cause of WA. And why do I get compilation error using Visual C 2010? It's ignoring semicolons. Sorry for this topic, I just initialized array to -1 instead of zero, and tested against it. #include <iostream> using namespace std; int main() { int a=1, b=5, sum=0; sum=a+b; cout<<sum<<endl; return 0; } Ты вводишь два числа, а не определяешь в коде. А система проверки может дать тебе любые два числа, не обязательно a=1 и b=5 ты должен ввести входные данные выводные данные Time limit exceeded Test №3 С# using System; public class Test { private static void Main() { ushort n = ushort.Parse(Console.ReadLine()); string result = ""; int t; for (ushort i = 0; i < n; i++) { t = int.Parse(Console.ReadLine()); if (Math.Sqrt((8 * t) - 7) % 1 == 0) result += " 1"; else result += " 0"; } Console.WriteLine("{0}", result); } } Whats wrong? [code deleted] Edited by moderator 19.11.2019 22:49 [code deleted] Edited by moderator 19.11.2019 22:50 [code deleted] Edited by author 07.10.2014 17:38 Edited by moderator 19.11.2019 22:50 [code deleted] Edited by moderator 19.11.2019 22:50 Try test 3 1 10 2 20 2 30 Edited by author 20.03.2007 21:45 #include <stdio.h> __int64 n, i, a[200002], b[200002], mx; void solve(){ a[1] = b[1] = mx = 1; for(i = 1 ; i < 100001 ; i ++){ a[i << 1] = a[i]; a[i << 1 | 1] = a[i] + a[i + 1]; if(mx < a[i]) mx = a[i]; b[i] = mx; } while(~scanf("%I64d", &n)){ if(!n) break; printf("%I64d ", b[n]); } } int main(){ solve(); } my code: #include<iostream> #include<cmath> using namespace std; main() { unsigned int n,temp,nc; cin>>n; nc=n; temp=sqrt(n); if(n==0) cout<<0; else if(temp*temp==n) cout<<1; else { unsigned int x=-1,m=0,q=4,t; for(unsigned int i=temp;i>=1;i--) { t=i; while(x!=0) { x=n-t*t; n=x; t=sqrt(x); m++; } if(m<q) q=m; if(m==2) break; x=-1; m=0; n=nc; } cout<<q; } } Accepted... public class CipherMessage1654_Accepted { public static void main(String[] args) { Stack<Character> stack = new Stack<Character>(); Scanner x = new Scanner(System.in); String s = x.nextLine(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) >= '`' && s.charAt(i) <= '9' || s.charAt(i) >= 'a' && s.charAt(i) <= 'z') { if (stack.isEmpty()) { stack.push('`'); } if (s.charAt(i) != stack.peek()) stack.push(s.charAt(i)); else stack.pop(); } } for (int i = 0; i < stack.size(); i++) { if (stack.get(i) != '`') System.out.print(stack.get(i)); } } } Edited by author 16.12.2014 09:49 |
|