| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| WA3--C#--Help! | roshan | 1002. Телефонные номера | 11 окт 2016 17:46 | 2 |
hello,i got wa3.can you tell me why?or give me some tests.thank you very much! the source: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Timus1003 { class Program { static void Main(string[] args) { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; List<Phone> arrayList=new List<Phone>(); while(true) {
string phoneNumber=Console.ReadLine(); if(phoneNumber=="-1") { break; } Phone phone = new Phone(); phone.PhoneNumber =phoneNumber ; phone.Size =Convert.ToInt32(Console.ReadLine()); string[] dics = new string[phone.Size]; int n=0; while(n<phone.Size) { dics[n] = Console.ReadLine(); n++; } phone.Dics = dics; arrayList.Add(phone); } // Console.WriteLine("out"); for(int i=0;i<arrayList.Count;i++) {
Phone phone = arrayList[i]; phone.Dics = phone.Dics.OrderByDescending(s => s.Length).ToArray<string>(); String[] str = new String[phone.Dics.Length]; for(int j=0;j<phone.Dics.Length;j++) { str[j] = wordToNumber(phone.Dics[j]); } phone.HasSolution=find(phone.PhoneNumber, str, phone); if(phone.HasSolution) { string solutionStr = ""; for(int k=0;k<phone.Solutions.Count;k++) { if(k==phone.Solutions.Count-1) { solutionStr = solutionStr + phone.Solutions[k] + ""; } else { solutionStr = solutionStr + phone.Solutions[k] + " "; }
} Console.WriteLine(solutionStr); } else { Console.WriteLine("No solution."); } } Console.ReadLine();
} public static bool find(string phoneNumber,string[] dics,Phone phone) {
for (int i = 0; i < dics.Length;i++ ) { // if (phoneNumber == "") return true; if (phoneNumber == dics[i]) { phone.Solutions.Add(phone.Dics[i]); //Console.Write(phone.Dics[i] + " "); return true; }
if (phoneNumber.IndexOf(dics[i]) == 0) { phone.Solutions.Add(phone.Dics[i]); // Console.Write(phone.Dics[i] + " "); string newPhoneNumber = phoneNumber.Substring(dics[i].Length); if(find(newPhoneNumber, dics, phone)) { return true; } else { phone.Solutions.RemoveAt(phone.Solutions.Count-1); continue; }
}
} // Console.WriteLine("No solution."); return false; }
public static string wordToNumber(string word) { char[] wordArr = word.ToCharArray(); char[] numArr = new char[wordArr.Length]; for (int i = 0; i < wordArr.Length;i++ ) { numArr[i] = charToNumber(wordArr[i]); } return new String(numArr); } public static char charToNumber(char mychar) { switch(mychar) { case 'i': case 'j': return '1'; case 'a': case 'b': case 'c': return '2'; case 'd': case 'e': case 'f': return '3'; case 'g': case 'h': return '4'; case 'k': case 'l': return '5'; case 'm': case 'n': return '6'; case 'p': case 'r': case 's': return '7'; case 't': case 'u': case 'v': return '8'; case 'w': case 'x': case 'y': return '9'; case 'o': case 'q': case 'z': return '0'; default: return mychar; }
} } class Phone { string phoneNumber; public string PhoneNumber { get { return phoneNumber; } set { phoneNumber = value; } } int size; public int Size { get { return size; } set { size = value; } } string[] dics; public string[] Dics { get { return dics; } set { dics = value; } } List<string> solutions = new List<string>(); public List<string> Solutions { get { return solutions; } set { solutions = value; } } bool hasSolution; public bool HasSolution { get { return hasSolution; } set { hasSolution = value; } } } } If I understood your algorithm properly, you intent to get best result with sorting you dictionary by word length and trying words from longest to shortest, but it's not always true. For example, let's test contains words with lengths 5 3 2 1, and proper results are 5-2-1 and 3-5. Your algorithm will find the 5-2-1, and not 3-5. (It was my mistake too and I got WA3 as well.)))) |
| why it is wrong answer???sad... | xinxin | 1020. Ниточка | 10 окт 2016 19:02 | 3 |
#include<stdio.h.> #include<string.h> #include<math.h> int main() { double len=0; int n,r,i,j; scanf("%d %d",&n,&r); double a[200][2]; for(i=0;i<n;i++) for(j=0;j<2;j++) scanf("%lf",&a[i][j]); for(i=1;i<n;i++) len=len+sqrt((a[i][1]-a[i-1][1])*(a[i][1]-a[i-1][1])+(a[i][0]-a[i-1][0])*(a[i][0]-a[i-1][0])); len=len+sqrt((a[i-1][1]-a[0][1])*(a[i-1][1]-a[0][1])+(a[i-1][0]-a[0][0])*(a[i-1][0]-a[0][0])); len=len+3.141*2*r; printf("%.2lf",len); fflush(stdin); getchar(); return 0; } I guess the 8th and 9th line. The value of radius is a real number instead of an integer, which is considered to be with decimal point. Thus "double r;" "scanf("%d %lf", ..)" maybe works. Also note. Is pi=3.141 accurate enough? I used 3.14159 in my AC program |
| WA #15 | encrypted_swordsmen | 1019. Перекрашивание прямой | 10 окт 2016 12:20 | 1 |
WA #15 encrypted_swordsmen 10 окт 2016 12:20 First I got WA#11 . Found that a simple increase of size of array to 20005 gave AC #11. Now I'm stuck in #15. Anyone have a case? |
| C语言AC | xinxin | 1725. Аншлаг, аншлаг! | 9 окт 2016 18:30 | 1 |
C语言AC xinxin 9 окт 2016 18:30 #include "stdio.h" int main() { int n,i; scanf("%d %d",&n,&i); if(n==2) {printf("0"); return 0; } if(i<=n/2) printf("%d",n-i-2); else printf("%d",i-1-2); } |
| test 10......sad.... | xinxin | 1688. Team.GOV! | 9 окт 2016 16:25 | 1 |
#include "stdio.h" #include "stdlib.h" #include<string.h> int main() { long int m,n,sum=0,a[3001]; scanf("%ld %ld",&n,&m); for(int i=1;i<=m;i++) { scanf("%d",&a[i]); } n=n*3; for(int i=1;i<=m;i++) { sum+=a[i]; if(sum>=n) { printf("Free after %d times.",i); return 0; } } printf("Team.GOV!"); } |
| test 11 ......sad.... | xinxin | 1283. Гномик | 8 окт 2016 19:08 | 1 |
#include<iostream> using namespace std; int main() { double a,b,c,d,e,f=0; cin>>a>>b>>c; d=a*c*0.01; e=a-d; a=e; if(a<=b) { cout<<f; return 0; } f++; while(a>b) { d=a*c*0.01; e=a-d; a=e; f++; } cout<<f; return 0;} |
| Brave Ballons | Niveditha | 1049. Отважные воздухоплаватели | 7 окт 2016 20:50 | 2 |
import java.util.*; public class BallonNumber { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int a[]=new int[10]; int count=0; int prod=1,i; for(i=0;i<10;i++) { a[i]=sc.nextInt(); } for(i=0;i<10;i++) { prod=prod*a[i]; } //System.out.println(prod); for(i=1;i<=prod;i++) { if (prod%i==0) { count+=1;
} } System.out.println(count); } } So this is my code but it says wrong answer but I get the same answer in ide.What is wrong with this code Please estimate max value of prod. Then compare it with int capacity. |
| test 11 ......sad.... | xinxin | 1336. Проблема Бен Бецалеля | 7 окт 2016 20:06 | 1 |
#include<iostream> #include<stdlib.h> #include<math.h> using namespace std; int main() {long double n; long long int m,i; cin>>m;
for(i=1;i<10000000000000000000;i++) { n=sqrt(i*i*i*m); if(n==floor(n+0.5)) { cout<<n<<endl<<i;break;} } fflush(stdin); getchar(); return 0;} |
| test 11 ......sad.... | xinxin | 1336. Проблема Бен Бецалеля | 7 окт 2016 20:04 | 1 |
#include<iostream> using namespace std; int main() { double n; long long int m,i; cin>>m;
for(i=1;i<10000000000000000000;i++) { n=sqrt(i*i*i*m); if(n==floor(n+0.5)) { cout<<n<<endl<<i; break; } } fflush(stdin); getchar(); return 0; } |
| What is the answer | Mehas | 1476. Лунокод | 5 окт 2016 16:36 | 3 |
...for test 40 40 40? My is 32460430015431999968619493682032835511850959272235390105491169601 Too small... Obviously, the answer is 2^1600 = (2^10)^160 ~ (10^3)^160 ~ 10^480 Right answer is 44462416477094044... Edited by author 05.10.2016 16:36 |
| WA#6 | Ilya (Vologda SPU) | 1576. Телефонные тарифы | 5 окт 2016 13:57 | 4 |
WA#6 Ilya (Vologda SPU) 29 окт 2009 00:40 I got WA#6, what is wrong? Re: WA#6 Oleg Strekalovsky [Retired] 30 окт 2009 12:51 Send to me your solution - and I will try to find your mistake Edited by author 30.10.2009 22:44 Re: WA#6 Oleg Strekalovsky [Retired] 30 окт 2009 22:47 I found your mistake. Test 0 1 0 20 0 300 1 25:00 right Answer: Basic: 25 Combined: 0 Unlimited: 300 Edited by author 30.10.2009 22:47 Re: WA#6 Husanboy Abdullayev 5 окт 2016 13:57 I gave this test and took right answer: Basic: 25 Combined: 0 Unlimited: 300 but again WA#6. Why? Help me, please |
| WA at test#5 | Gopesh Tulsyan | 1073. Квадратная страна | 5 окт 2016 10:30 | 5 |
I am getting a WA at test #5 Here's my code : #include <iostream> using namespace std; int main(){ int n,i=1,count=0; cin>>n; while(n>0){ if(i*i<=n) i++; else{ n-=(i-1)*(i-1); i=1; count++; } } cout<<count<<endl; return 0 } Imagine you are given the following input: n=72. Given that 72 = 6*6 + 6*6 the answer should be 2, but your output is 3. This is happening because you are solving the problem using a greedy strategy. Here a greedy strategy does not work. If you want more information on why this technique does not work read chapter 15 and 16 of "Introduction to algorithms" by Cormen,Leiserson,Rivest and Stein. Thanks for the explanation... ^_^ 60000 Edited by author 05.10.2016 10:30 |
| accepted pure c code | Иван | 1068. Сумма | 4 окт 2016 22:29 | 2 |
#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char *argv[]) { int n, tmp; long sum; scanf("%d", &n); if (n > 10000 || n < -10000) { printf("%d\n", 0); return 0; } if (n == 0) { printf("%d\n", 1); return 0; } if (n > 0) { /* positive */ if (n % 2 == 0) { /* even */ sum = n * (n / 2 - 1) + n + (n / 2); } else { /* not even */ sum = n * (n / 2) + n; } } else { /* negative */ if (n % 2 == 0) { /* even */ sum = n * (n / 2 + 1) - n - (n / 2) - 1; tmp = ~sum + 1; sum = tmp; } else { /* not even */ sum = n * (n / 2) - n - 1; tmp = ~sum + 1; sum = tmp; } } printf("%ld\n", sum); return 0; } /* n * (n / 2) + n not even */ /* n * ((n / 2) - 1) + n + (n / 2) even */ /* n * (n / 2) - n - 1 negative not even */ /* n * ((n / 2) + 1) - n - (n / 2) - 1 negative even */ #include<stdio.h> int main(){ int n,N,ans; scanf("%d",&N); if(N > 1){ n=N; }else{ n=-1*N+2; } ans=(n*(N+1))/2; printf("%d\n",ans); return 0; } Also accepted |
| What's wrong in this? (C#) | gholamali | 1068. Сумма | 4 окт 2016 22:25 | 3 |
using System; namespace gholamali { class Program { static void Main(string[] args) { try { int N = Convert.ToInt32(Console.ReadLine()); if (Math.Abs(N) <= 10000) { if (N > 1) Console.Write(((N + 1) / 2) * N); else Console.Write(((N + 1) / 2) * (2 - N)); } Console.ReadKey(); } catch { } } } } [TestCase("2", "3")] ((N + 1) / 2) * N when you divide on int (= 2) it produce int result (= 1) and total sum is wrong (= 2) (N + 1) / 2) * N First multiply and then divide by 2 Like (N + 1) *N) / 2 Otherwise it may not act like an integer. and for second case ((N + 1) * (2 - N)) / 2 Edited by author 04.10.2016 22:27 |
| Python got TLE16 on O(m*n) solution, C++ got AC even with Dijkstra. Please add PyPy! | Practician | 1325. Грязь | 4 окт 2016 14:32 | 1 |
My old C++ solution got AC with optimized Dijkstra, O(v*log(v)), where v = m*n. The timing was 0,406 sec. Evidently, with Python (2.7, 3.4) I got TLE with the same solution. On my machine 500*500 case runs for 4.5 seconds. Then I realized O(m*n) solution and optimized input as much as possible (Python). It still gives TLE16, on my machine - runs for 2.3 seconds. Then I run code under PyPy (5.4.1, Python2.7 compatible) and on my machine it runs for 0.383 seconds only. I hope it would AC if PyPy is able to be selected as a programming language. Please add PyPy! Thanks |
| How to prove four cells is enough? | riparia | 1552. Brainfuck | 3 окт 2016 22:17 | 1 |
|
| what is the test 7? | organmusic | 1801. Кубок Революции | 3 окт 2016 19:09 | 2 |
I have also got WA in the test 7. Is it necessary to sort the teams names before output? Edited by author 22.05.2015 03:17 Edited by author 22.05.2015 03:43 have you figured out what went wrong? I'm having the same problem with test #7 here... thanks |
| Java optimization tips | vlyubin | 1620. Clever House | 3 окт 2016 13:50 | 2 |
Hey, do the guys that submit on Java use BigInteger and array of (2 x BigInteger)[2000][1000]? If yes, then how do they manage to pass the TL? Is it just a matter of Java optimization, or the solution is much harder than a simple DP? Thanks ! Edited by author 07.04.2012 06:11 It's more of a math problem than DP... If you find the right pattern the solution is pretty simple and no optimization trick is needed to pass time limit. good luck! |
| Problem 1200 Horns and Hoofs has been rejudged | Vladimir Yakovlev (USU) | 1200. Рога и копыта | 3 окт 2016 05:30 | 3 |
New tests have been added. All solutions have been rejudged: 288 authors have lost AC. Hm, TL #2 after rejudge... apparently old tests are changed too. Edit: i see, thanks~ Edited by author 03.10.2016 12:11 Old tests haven't been changed. Your solution's verdict on test #2 has changed from "slightly under TL" to "slightly above TL". There were a few such cases in total. |
| WA#33 | Anton juver++ Postnikov | 1280. Topological Sorting | 2 окт 2016 22:16 | 9 |
WA#33 Anton juver++ Postnikov 25 июн 2006 01:42 Who can give me some tricky tests for this problem, please! May be you need a more tricky algo? It's unable to have WA with this problem (quite simple algo) Please help, i have the same problem but i don't know where is my error here is code #include <iostream> using namespace std; int power[1005]; int deg[1005]; int mas[1005][1005]; int n,m; int answers[1006]; void input() { cin>>n>>m; int a,b; for(int i=0;i<m;i++) { cin>>a>>b; mas[a][power[a]++] = b; deg[b]++; } for(int i=0;i<n;i++) cin>>answers[i]; } void solve() { for(int i=0;i<n;i++) { if (deg[answers[i]]>0) { cout<<"NO"; return; } for(int j=0;j<power[answers[i]];j++) deg[mas[answers[i]][j]] --; } cout<<"YES"; } int main() { input(); solve(); return 0; } Re: WA#33 Nechaev Ilya (Rybinsk SAAT) 10 ноя 2006 04:00 I don't know what are you doing, but you need just check M conditions for given sequence. I don't know what can be wrong. Edited by author 10.11.2006 04:29 Re: WA#33 Nechaev Ilya (Rybinsk SAAT) 10 ноя 2006 04:20 Haha. I just changed int mas[1005][1005]; to int mas[1005][10005]; and get AC. I think that each limitation can occur in the input more than once i.e. some limitations can be equal :-p Advice: this solution use too much memory. Really you need less than 1 Mb. Edited by author 10.11.2006 14:02 Thank you for advise. Now i just changed adjanced list stored in array to vector<vector<int> > . And my programm used only 860 Kb. Haha. I just changed int mas[1005][1005]; to int mas[1005][10005]; and get AC. I think that each limitation can occur in the input more than once i.e. some limitations can be equal :-p Advice: this solution use too much memory. Really you need less than 1 Mb. Edited by author 10.11.2006 14:02 I'm very appreciate you. I used vector<vector<int> > and eventually got AC:-) Thank you for the advice about limitations! |