| Show all threads Hide all threads Show all messages Hide all messages |
| please help | milky | 1029. Ministry | 21 Apr 2015 14:08 | 1 |
|
| Wrong answer 32 | Nextatix | 2033. Devices | 20 Apr 2015 13:33 | 1 |
import java.io.*; import java.util.*; //import java.math.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); //String[] name = new String[6]; String[] device = new String[6]; int[] price = new int[6]; Map<String,Integer> result = new TreeMap<String,Integer>(); Map<String,Integer> rprice = new TreeMap<String,Integer>();
for(int i=0; i<6; i++) { in.readLine(); device[i] = in.readLine(); price[i] = Integer.parseInt(in.readLine());
if(!result.containsKey(device[i])) { result.put(device[i],1); rprice.put(device[i],price[i]); } else { result.put(device[i],result.get(device[i])+1); if(price[i]<rprice.get(device[i])) rprice.put(device[i],price[i]); } } int rep = 1, max = 1; for(int i : new ArrayList<Integer>(result.values())) { if(max==i) rep++; if(max<i) { rep = 1; max = i; } }
if(rep==1) { for(String i : result.keySet()) if(max==result.get(i)) out.print(i); } else { int min=0; for(String i : rprice.keySet()) { if(max==result.get(i)) { if(min==0) min=rprice.get(i); else if(min>=rprice.get(i)) min=rprice.get(i); } } for(String i : rprice.keySet()) { if(min==rprice.get(i)) out.print(i); } } out.flush(); } } |
| What answer if N<M ? | Ilya | 1055. Combinations | 20 Apr 2015 01:38 | 2 |
There is no such input. From statement: Input contains integers N and M. You may assume that 1 ≤ M < N ≤ 50000. |
| Optimization | Pavlik | 1362. Classmates 2 | 19 Apr 2015 22:03 | 8 |
I accepted 0.39(5kb). I use template veckor class(C++) to store list of employees. But I don't know how make my program faster :( Edited by author 30.09.2008 14:40 Edited by author 30.09.2008 14:51 Don't use vectors - these are VERY slow structures (as, by the way, all STL components). Rewrite with usual arrays - and, I think, speed of your code will increase several times... i use vector too, i think if i got use array memory limit have exceeded. Don't use vectors - these are VERY slow structures (as, by the way, all STL components). Rewrite with usual arrays - and, I think, speed of your code will increase several times... This statement is just wrong. In which part? For any STL component I can write much faster analog. Well, I was refering only to vectors. Of course you can make sets/maps/other stuff faster. But the underlying structure of a vector is the same array. E.g. vector<int> is just a {array pointer, size, reserved mem}. I've heard this myth about vectors being slow several times, that's exactly why I've done some real testing of it - absolutely no difference, especially if you give the size beforehand (which you have to do in case of arrays). Actually, if you use an iterator to iterate through your vector, it can sometimes actually be faster for different reasons. The only difference may come from using multidimensional (i.e. nested) vectors - in that case, indeed, there can be some performance differences, but still, saying "VERY slow structures" is an extreme exaggeration... remember, you said "increase several times" :). Edited by author 02.04.2011 02:12 |
| WA 4 | MOPDOBOPOT (USU) | 2019. Pair: normal and paranormal | 19 Apr 2015 20:53 | 7 |
WA 4 MOPDOBOPOT (USU) 11 Oct 2014 16:34 Someone have interesting tests? :) Re: WA 4 BinaryMind [RAU] 12 Oct 2014 18:17 Try this: 2 AAaa Answer: 2 1 Edited by author 12.10.2014 18:17 Also try AbaBbABa. Solution should be: 4 3 2 1 aaAAbBAa should be 2 1 3 4 Re: WA 4 SButterfly [Samara SAU] 13 Nov 2014 22:29 3 AAaAaa 3 1 2 4 bAaAAaaB 2 4 3 1 5 BAaAAaaCcb 5 1 3 2 4 5 bAaAaAacCB 2 3 4 5 1 Try this: 4 ACcabdDB my solution passes all mention above, but failed on this... Should be: 2 1 4 3 Some random tests and right answers: 4 CAaDBbdc Answer: 4 1 3 2 4 AbBcCdDa Answer: 4 1 2 3 5 AaBbCDAadc Answer: 1 2 5 4 3 5 AbCdEeDcBa Answer: 5 4 3 2 1 Good luck! |
| 1083__ | Konjoh Elvis | 1083. Factorials!!! | 19 Apr 2015 19:56 | 1 |
1083__ Konjoh Elvis 19 Apr 2015 19:56 Can k be gretter than n if possible what should we do in this case? |
| Don't know this is wrong | Konjoh Elvis | 1068. Sum | 19 Apr 2015 18:14 | 1 |
import java.io.PrintStream; import java.util.Scanner; public class _1068 {
PrintStream out ; Scanner sc; public _1068() { try { sc = new Scanner(System.in); out = System.out; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } protected void run() throws Exception { int n = sc.nextInt(); int nb = Math.abs(n); if(n<0) nb+=2; out.println(((nb)*(n+1))/2);
sc.close(); out.close(); } public static void main(String args[]) throws Exception { new _1068().run(); } } |
| Test 5 failure - Please help!. | ElPsyCongroo | 1020. Rope | 19 Apr 2015 17:06 | 3 |
My code below is failing at test 5. Please help me. import java.io.BufferedReader; import java.io.InputStreamReader; import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class Cryptography1086 { public static void main( String[] args ) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
StringTokenizer st = new StringTokenizer( br.readLine() );
int numberOfNails = Integer.parseInt( st.nextToken() );
double radiusOfNails = Double.parseDouble( st.nextToken() );
double lengthOfRope = 2 * Math.PI * radiusOfNails;
st = new StringTokenizer( br.readLine() ); double x0 = Double.parseDouble( st.nextToken() ); double y0 = Double.parseDouble( st.nextToken() ); if( numberOfNails == 1 ) { DecimalFormat df = new DecimalFormat( "#.00" );
System.out.println( df.format( lengthOfRope ) ); return; }
double xStore = x0; double yStore = y0;
double xK = 0; double yK = 0;
for( int inx = 1 ; inx < numberOfNails; ++inx ) { st = new StringTokenizer( br.readLine() );
xK = Double.parseDouble( st.nextToken() ); yK = Double.parseDouble( st.nextToken() );
double dx = Math.pow( (xK - x0), 2 ); double dy = Math.pow( (yK - y0), 2 );
double dxy = Math.sqrt( dx + dy );
lengthOfRope += dxy;
x0 = xK; y0 = yK; }
double d1 = Math.pow( (xK - xStore), 2 ); double d2 = Math.pow( (yK - yStore), 2 ); lengthOfRope += Math.sqrt( d1 + d2 );
DecimalFormat df = new DecimalFormat( "#.00" );
System.out.println( df.format( lengthOfRope ) ); } } The problem was my usage of DecimalFormat df = new DecimalFormat( "#.00" ); It should have been something like this: DecimalFormat df = new DecimalFormat( "0.00" ); Note the '#' to '0' change. You are correct, but what is the difference between the two thing? |
| TLE #12, How to make my code sound?? | Neeraj Kumar | 1100. Final Standings | 19 Apr 2015 13:57 | 1 |
#include <iostream> int main() { int data[150000][2],i,j,n,step,temp;
std::cin >> n; std::cin.ignore(255, '\n'); for(i=0;i<n;++i) {
for (j = 0; j < 2; ++j)
std::cin>> data[i][j]; std::cin.ignore(255, '\n'); } j = 1; bool is_sorted; for(step=0;step<n-1;++step){ is_sorted = true; for(i=0;i<n-step-1;++i) {
if(data[i][j]<data[i+1][j]) { temp=data[i][j]; data[i][j]=data[i+1][j]; data[i+1][j]=temp;
temp = data[i][0]; data[i][0]=data[i+1][0]; data[i+1][0] = temp;
is_sorted = false; }
} if(is_sorted) break; } for(i=0;i<n;++i){ for (j =0 ; j < 2; ++j){ std::cout<<data[i][j]<<' '; } std::cout<<'\n'; }
return 0; } |
| Little trick: if you are getting W3, or W5 or whatever | Nodir NAZAROV [TUIT-Karshi] | 2023. Donald is a postman | 19 Apr 2015 13:07 | 3 |
use simple algorithm: - checks only initial. - keep state of previous - initial state of previous is 1, since postman is in leftmost case useful test cases: ---- 1 Bambi 1 (not 0, because he moves to second case with one step) ---- 1 Alice 0 ---- 1 Dumbo 2 --- WA 5, but test is true( sorry, because I don't know English:) Didn't get your testcase; if Bambi, Alice and Dumbo are the Kids, the answer should be 3, right? |
| WA #4 | David Yin [ECUPL] | 1085. Meeting | 18 Apr 2015 19:19 | 1 |
WA #4 David Yin [ECUPL] 18 Apr 2015 19:19 Why that? Who can give me the test case that will fail like this? |
| Solution for C++ Test #20 TLE | Jumabek Alikhanov | 1330. Intervals | 18 Apr 2015 09:48 | 1 |
Use scanf and printf instead of cin,cout. I had a really hard time to figure it out)) |
| #8 Any Help please | engineer_islam | 1640. Circle of Winter | 18 Apr 2015 01:50 | 1 |
#include<iostream> #include<cmath> #include<iomanip> #include<vector> using namespace std; struct p { double rec1; double rec2; }; int main() { vector<int> v; int n; cin>>n; if(1<=n&&n<=100) { int *ptr=new int[n*2]; for(int i=0;i<(n*2);i++) cin>>ptr[i]; if(n==1) { if(ptr[0]==0) cout<<ptr[0]+1<<" "<<ptr[1]<<" "<<1; else cout<<ptr[0]-1<<" "<<ptr[1]<<" "<<1; system("pause"); return 0; } int lessx=0,highx=0,lessy=1,highy=1; for(int i=2;i<(n*2);i+=2) { if(ptr[i]<ptr[lessx]) lessx=i; if(ptr[i]>ptr[highx]) highx=i; if(ptr[i+1]<ptr[lessy]) lessy=i+1; if(ptr[i+1]>ptr[highy]) {
v.clear(); highy=i+1; v.push_back(i+1); } else if(ptr[i+1]==ptr[highy]) v.push_back(i+1);
}
int point[2]; point[0]=(ptr[lessx]+ptr[highx])/2.0; point[1]=(ptr[lessy]+ptr[highy])/2.0; for(int i=0;i<(n*2);i=i+2) { if(ptr[i]==point[0]) { if(ptr[i+1]==point[1]) { point[1]++;
} } } cout<<point[0]<<" "<<point[1]<<" "; int p1,p2,max,min; if(v.size()>=2) { p1=highy;max=v[0]-1;p2=highy;min=v[0]-1; for(int i=1;i<v.size();i++) { if(ptr[v[i]-1]>point[0]) { if(ptr[v[i]-1]>ptr[max]) p1=v[i]; } else if(ptr[v[i]-1]<ptr[min]) p2=v[i]; } } int highp_y[2]; if(v.size()>=2) { if((ptr[p1-1]-point[0])>(point[0]-ptr[p2-1])) { highp_y[0]=ptr[p1-1]; highp_y[1]=ptr[p1]; } else { highp_y[0]=ptr[p2-1]; highp_y[1]=ptr[p2]; } } else { highp_y[0]=ptr[highy-1]; highp_y[1]=ptr[highy]; } int lessp_x[2]; lessp_x[0]=ptr[lessx]; lessp_x[1]=ptr[lessx+1]; double longr[2]; p s; for(int i=1;i<=2;i++) { if(i==1) { s.rec2=point[0]-lessp_x[0]; if(lessp_x[1]>point[1]) s.rec1=lessp_x[1]-point[1]; else s.rec1=point[1]-lessp_x[1];
longr[0]=sqrt((s.rec1*s.rec1)+(s.rec2*s.rec2));
} else { s.rec1=highp_y[1]-point[1]; if(point[0]==highp_y[0]) { longr[1]=s.rec1; break; } else { if(point[0]>highp_y[0]) s.rec2=point[0]-highp_y[0]; else s.rec2=highp_y[0]-point[0]; longr[1]=sqrt((s.rec1*s.rec1)+(s.rec2*s.rec2)); } } } cout<<fixed<<setprecision(9); if(longr[0]>longr[1]) cout<<longr[0]; else cout<<longr[1];
system("pause"); return 0; } system("pause"); return 0; } |
| WTF TLE#9 | Tigran Hakobyan | 1992. CVS | 17 Apr 2015 13:16 | 1 |
O(n) solution got TLE on test 9 ! |
| wa #7 | SLHUNG | 1801. The Revolution Cup | 16 Apr 2015 08:33 | 1 |
wa #7 SLHUNG 16 Apr 2015 08:33 |
| WA#2 | Shervin | 1960. Palindromes and Super Abilities | 15 Apr 2015 18:11 | 2 |
WA#2 Shervin 12 Feb 2015 02:50 I may be wrong but it might be something like this. for (int i = 0; i < 1 << 16; i++) cout << (char)('a' + __builtin_popcount(i) % 2); Edited by author 15.04.2015 18:12 |
| Problem 1905. Travel in Time rejudged | Problemset Maintainer | 1905. Travel in Time | 15 Apr 2015 09:49 | 1 |
New tests have been added, 24 authors have lost AC. |
| Test # 13 why? | AlexRad | 1964. Chinese Dialects | 14 Apr 2015 09:35 | 1 |
var min1 = n; var min2 = n; for (var i = 0; i < k; i++) { var a = vals[i]; if (a < min1) { min2 = min1; min1 = a; } else if (a < min2) min2 = a; } Console.WriteLine(Math.Max(min1 + min2 - n, 0)); |
| Little hint for test #8 | s.egorov | 2030. Awesome Backup System | 13 Apr 2015 23:51 | 1 |
If you get WA on test #8, don't forget about mod = 1000000007 :) |
| WA3 ??? | hailoc12 | 1452. Pascal vs. C++ | 13 Apr 2015 23:17 | 1 |
Can somebody give me some hints on Test 3 ? I get WA but don't know why. I 've run all other test in the forum and it gives right answer |