Общий форумIn a different IDE with all boundary conditions checked, it's working but it shows run-time error at test #8, not sure why. import sys def compute_sum(n): return int(n[0]) + int(n[1]) + int(n[2]) - int(n[3]) - int(n[4]) - int(n[5]) n = input() s2 = 1 s3 = 1 if int(n) == 0 or int(n) == 999999: print ('Yes') sys.exit() s1 = compute_sum(n) if len(str(int(n))) < 6: d = 6 - len(str(int(n))) s2 = compute_sum('0' * d + str(int(n) - 1)) s3 = compute_sum('0' * d + str(int(n) + 1)) else: s2 = compute_sum(str(int(n) - 1)) if len(str(int(n) + 1)) <= 6: s3 = compute_sum(str(int(n) + 1)) if abs(s2) == 0 or abs(s3) == 0: print ("Yes") else: print ("No") Jane Soboleva (SumNU) New year! 1 янв 2016 04:30 Happy new year, contestants, authors and admins! May this next year bring you happiness, enthusiasm, more AC submits and all that stuff~ Hooray \o/ here's my code.Please give me some advise or test data! int n = int.Parse(Console.ReadLine()); int nCopy = n; int sum = 0; string[] array = new string[2]; short digitSum = 0; while(n-- != 0) { digitSum = 0; array = Console.ReadLine().Split(' '); foreach(var i in array) { digitSum += short.Parse(i); } sum += digitSum * (int)Math.Pow(10, n); } Console.WriteLine(sum.ToString().Length > nCopy ? sum.ToString().Substring(1):sum.ToString().PadLeft(nCopy,'0')); From task description: > (1 ≤ N ≤ 1 000 000) Why do you think you are able to put result into 32-bit (10 digits max) int variable? can anyone tell me how to solve this question in short memory usage which is less than o(n*a) or o(n*b) i will be very thankful to you please help me :D here is my code #include <stdio.h> #include <stdlib.h> int main() { int n,o,t;scanf("%d %d %d",&n,&o,&t); int a[500][300]={0}; int b[500][300]={0}; int i,j,k; for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { if(j>o) break; if(j==i) if(j<=o) a[i][j]=1; ///which shows it is valid a[i][j]=a[i][j]+b[i-j][0]; ///as the places inc with j we will inc in the table of other above } for(k=1;k<=o;k++) a[i][0]+=a[i][k]; ///total sum of all for(j=1;j<=i;j++) { if(j>t) break; if(j==i) if(j<=t) b[i][j]=1; ///which shows it is valid b[i][j]=b[i][j]+a[i-j][0]; ///as the places inc with j we will inc in the table of other above } for(k=1;k<=o;k++) b[i][0]+=b[i][k]; ///total sum of all } printf("%d\n",a[n][0]+b[n][0]); return 0; } Edited by author 13.12.2015 01:13 I used idea: State is - for L songs album there are Sa1, Sa2, ... Saa - counts of albums ends with 1, 2, ... a "My love" songs; Sb1, Sb2, ... Sbb - counts of albums ends with 1, 2, ... b "I miss you" songs. Total state size is a+b int counters. There is only L state required to calculate (L+1) state. Edited by author 29.12.2015 22:25 What's on test 6? help, please! a=int(input()) b=int(input()) print(a+b) Edited by author 26.12.2015 17:28 1000 => 501501000 500 => 62875500 333 => 18629685 1 => 3 3 => 30 4 => 60 and use long long =) Sorry for my bad english I'm see all exists tests, and I'm get a correct result on these tests(according comments). Let <ms> is init array, <flag> is (answer is YES?). 1. I do check that (the number in <ms>) is not greater than <n> 2. I'm sorted <ms>. 3. I'm create a <isFills> = new Array[Boolean](n+1) And then I use the following code: if (m>1 && ms(1) == 0) return false // (ms(0)==ms(1)==0) => "NO" if (m>1 && ms(m-2)==n) return false // (ms(m-2)==ms(m-1)==n) => "NO"
isFills(max(ms(0)-1, 0)) = true for (i <- 1 until m) { if (!isFills(ms(i)-1) || !isFills(ms(i))) { if (!isFills(ms(i)-1)) isFills(ms(i)-1) = true else isFills(ms(i)) = true } else return false } return flag Console.println(if (getFlag==true) "YES" else "NO") Full code: object Main { import java.util.Scanner import math._
val scan = new Scanner(System.in) val n = scan.nextInt() val m = scan.nextInt() val ms = new Array[Int](max(m,1)) for (i <- 0 until m) ms(i) = scan.nextInt() scan.close()
def getFlag: Boolean = { var flag = true
for (i <- 0 until m) flag &&= ms(i)<=n if (!flag) return flag
java.util.Arrays.sort(ms) val isFills = new Array[Boolean](n+1)
if (m>1 && ms(1) == 0) return false if (m>1 && ms(m-2)==n) return false
isFills(max(ms(0)-1, 0)) = true for (i <- 1 until m) { if (!isFills(ms(i)-1) || !isFills(ms(i))) { if (!isFills(ms(i)-1)) isFills(ms(i)-1) = true else isFills(ms(i)) = true } else return false } flag } Console.println(if (getFlag==true) "YES" else "NO")
def main(args: Array[String]){} } Edited by author 26.12.2015 23:56 Edited by author 26.12.2015 23:57 my program just does dfs three times on the graph.... and so has order O(|n| + |e|) where n is number of nodes and e is edges till gives TLE in case 21... :( do we need a better algorithm than this as well...? Can any body tell me whai is in the test case 5...??? My code seems right but everytime it says WA#5... 200000 char in test case #5!! Thanksss.. It helped me a lot... Edited by author 25.12.2015 13:35 Edited by author 24.12.2015 20:50 Edited by author 24.12.2015 20:50 Я переписала это на джаве, используя BigInteger и BigDecimal и получила AC. (Спасибо~) Вообще, если возникают большие числа, то сейчас такие задачи легче всего решаются на джаве. UPD: Не за что~ Edited by author 25.12.2015 03:26 Спасибо за советы.Очень бесят задачи,где многое зависит от сложной технической реализации. Can anybody help me with this test case? Accepted with additional check if (2*h - l < 0.0) { cout << "butter"; return 0; } Can anyone help with this? I do not print at the end of an empty string. all the tests of the discussions my program passes. maximize amount of teams, but minimize max amount of fighters in a team. For example, if n=9, k=5, you should make 5 teams this way: (2, 2, 2, 2, 1) Tests: Input: 3 7 4 9 4 12 5 Output: 18 30 57 Edited by author 23.12.2015 22:42 I used a little different approach from the one mentioned on this board. It was based on weighted quick-union described by Sedgewick... I made a stupid logical mistake which caused my program to work the longest time possible, so first I got TLE#10 (solutionID=861144). Then I optimized my code with path compression (see Sedgewick once again) and got AC in 0.125 sec (solutionID=861147). Then I realized my error, removed path compression and got AC in 0.078 s (solutionID=861151). Adding path compression back slowed my solution a bit (0.109 s, solutionID=861153). All my solutions consume 449 KB of memory. I'm interested in time and memory requirements of other possible algorithms. I haven't got their implementations, so I cann't submit them myself. If somebody feels interested about my approach to this problem, just let me know - I'll explain. Edit my first comment, see the next one for complete explanation. I can share my code via email if you don't have an access to it. Edited by author 21.12.2015 22:46 My AC solution fails on following test 3 100 71 70 99 1 -71 70 It returns YES +-+ which means (71; 70) - (99; 1) + (-71; 70) = (-99; 139), |(-99; 139)|~170.65 > 141.4. But it is really strange that my AC solution contains awful mistake in sorting. In fact, sort doesn't work at all in my AC solution and output depends on vectors order! I wonder how could this code pass all tests. And I wonder how the code with fixed sorting (but still incorrect) fails on 53-th test only. Please add mentioned test. Edited by author 21.12.2015 22:48 Running in my computer is OK,use use Visual C++ 2010. But in here (use Visual C++ 2013) is wrong answer. I don't understand. Help me, please! #include <iostream> using namespace std; int main(){ int a[100][100]; int n, x=0; cout<<"\Input n: "; cin>>n; for(int j=n-1,i=0;j>=0;j--){ int h=i,k=j; while(k<n) a[h++][k++]=++x; } for(int i=1,j=0;i<n;i++){ int h=i,k=j; while(h<n) a[h++][k++]=++x; } for(int i=0; i<n ;i++){ for(int j=0; j<n ;j++){ cout.width(4); cout<<a[i][j]; } cout<<endl; } cin.ignore(80,'\n'); cin.get(); return 0; } import java.util.Scanner; import java.util.Stack; public class CliperMessage_1654_Stack { public static void main(String[] arg1) { Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); Stack<Character> stc=new Stack<>(); sb.append(sc.nextLine()); if(sb.length()<=200000){ for(int i=0;i<sb.length();i++){ if(stc.isEmpty()||(stc.peek()!=sb.charAt(i))) stc.push(sb.charAt(i)); else if((stc.peek()==sb.charAt(i))) stc.pop();
}
StringBuilder sbn=new StringBuilder(); int j=0; while(!stc.empty()) sbn.insert(j++, ""+stc.pop()); System.out.println(sbn.reverse()); } } } |
|