Общий форумYou don't must develop hard solution. Your work should not payed many time. Just pay attention, and look again on tests. Attention will save your time. I am sorry, for my poor English. Good luck! Edited by author 18.10.2015 16:52 Нужен максимум из 4-х минимумов) Edited by author 11.11.2017 22:53 Edited by author 11.11.2017 22:53 I was trying to write TRIE for mnemonic words and DFS that tree with phone number. And I have failed. After that, I wrote just 2-D dimensional dynamic programming solution. DP[i] [j] is minimal number of words to memorize substring [i;j]. And I got success. Used Python. Just input, not stdin from sys. i think you only need 1 array instead of dp[i,j] So probably there is jury solution available on the internet So I have examined jury solution Looks too simple Can't believe it is able to solve the problem where do you find the jury solution? using System; namespace t1068{ class Program{ public static void Main(string[] args){ int n = int.Parse(Console.ReadLine()); int i = 0; while (n != 1){ if (n >= 1){ i+= n; n--; } else if (n <= 0){ i+= n; n++; } } Console.Write(i + 1); //Console.ReadKey(); } } } using System; class Puzzle { public static void Main() { var n = int.Parse(Console.In.ReadLine()); (int start, int end) = n > 1 ? (1, n) : (n, 1); int sum = 0; for (int i = start; i <= end; i++) sum += i; Console.WriteLine(sum); } } static int Proccess(int input) { if (input == 1) { return 2; } else if (input == 0) { return 1; } bool isInputNegative = false; if (input < 0) { input = input * -1; isInputNegative = true; } int sum = 0; for (int i = 1; i < input + 1; i++) { sum += i; } if (isInputNegative) { sum = sum * -1; sum++; } return sum; } more understandable :D Edited by author 11.11.2017 20:22 time 0.078 memory 3 350 kb. I use triplex tree. It is very interesting problem. I used plain arrays and got AC in 0.093 and 410 KB. Solution with std::set and hand-written memory allocator gets AC in 0.062 and 534 KB. Where I can find info about triplex tree? I used google, but nothing found... time 0.078 memory 3 350 kb. I use triplex tree. It is very interesting problem. #include <stdio.h> #include <iostream> using namespace std; int n, m, segRez[3004]; int segm1[3004]; char segm2[6005]; int main() { cin >> n >> m; for(int i = 0; i < n; ++i){ gets_s(segm2); for(int j = 0; j < m; ++j){ segRez[j] = segm1[j] + int(segm2[j<<1] - 48); segm1[j] = int(segm2[j<<1] - 48); if(j - 1 >= 0 && ((segRez[j - 1]|segRez[j])) == 3){ cout << "No"; return 0; } } } cout << "Yes"; } Here is my java code : import java.util.Scanner; public class Example{ public static void main(String []args){ Scanner in = new Scanner(System.in); int number1,number2,number3; int [] array; int position=0; boolean check=false; int sth; number1=in.nextInt(); number2=in.nextInt(); number3=in.nextInt(); array = new int[number2]; for(int i=0;i<=number2-1;i++){ sth=(int)Math.pow(i,number1); if((sth-number3)%number2==0){ array[position]=i; position++; check=true; }else if(i==number2-1 && check==false){ System.out.println(-1); System.exit(0); }
} for(int p=0;p<position-1;p++){ for(int j=p+1;j<position;j++){ if(array[p]>array[j]){ int t=array[p]; array[p]=array[j]; array[j]=t; } } } for(int i=0;i<position;i++){ System.out.print(array[i] + " "); } System.out.println(); } } I get an error on test#3 . And on my C++ solution i get an error on test#6. #include<iostream> #include<cmath> using namespace std; int main(void){ unsigned short int N,M,Y; cin>>N>>M>>Y; unsigned short int X[M]; unsigned short int position=0; bool some_check=false; int sth; for(int i=0;i<=M-1;i++){ sth=pow(i,N); if((sth-Y)%M==0){ X[position]=i; position++; some_check=true; } else if(i==M-1 && some_check==false){ cout<<-1<<endl; return 0; } } for(unsigned short int i=0;i<position-1;i++){ for(unsigned short int j=i+1;j<position;j++){ if(X[i]>X[j]){ swap(X[i],X[j]); } } } for(unsigned short int i=0;i<position;i++){ cout<<X[i]<<" "; } cout<<endl; return 0; } Please,any ideas ??? int main() { int n; string s1, s2; cin >> n >> s1 >> s2; s1 += s1; int pos = (int) s1.find(s2); switch ( pos ) { case -1: cout << -1; break; case 0: cout << 0; break; default: cout << n-pos; } return 0; } Unfortunately, your solution has been rejudged. :) string.find() is too slow. Good luck! ¿Any idea of why a code can pass all the tests except the test 6 ? I prove my code with this imput, and it works fine 7325189087 5 it your reality real our 4294967296 5 it your reality real our 213456 12 id a h lm aid aidhlm hl m dhlm ai aid hlm 2017697240238123468420176972402381234684201769724023812346842017697240238123468420176972402381234684 7 azipmwpbgqadtjafhmth azipmwpbgqadtjafhmth azipmwpbgqadtjafhmth azipmwpbgqadtjafhmth azipmwpbgqadtja azipmwpbgqadtjafhmthazipmwpbgqadtjafhmthazipmwpbgqadtjafhmthazipmwpbgqadtjafhmth fhmth 27386428376 0 97854668689678768 3 dfgdfhjghjdggzash dfgkjt nkhhdfsge 11111111111 5 ij jj ji j i 1234567890 5 bdh txo bdhkmp i kmp -1 the answer is : reality our No solution. aidhlm azipmwpbgqadtjafhmth azipmwpbgqadtjafhmthazipmwpbgqadtjafhmthazipmwpbgqadtjafhmthazipmwpbgqadtjafhmth No solution. No solution. ji ji ji ji ji i i bdhkmp txo This is my code: import time import sys sys.setrecursionlimit(100000) n = int(input("Enter N (for digits): ")) k = int(input("Enter K: ")) rangeVar = pow(k, n) - pow(k, n-1) starter = pow(k, n) - rangeVar counter = 0 start = time.clock() def calc(i): global starter, rangeVar, counter, n, k temp = str(i)
if i == pow(k, n): return counter else: for j in range(len(temp) - 1): if temp[j] == '0' and temp[j+1] == '0': counter += 1 calc(i+1)
calc(starter) end = time.clock() print(rangeVar - counter) print(end - start) Remove repetitions before applying your algo i.e.: sequences like 2 1 2 2 2 2 1 change into 2 1 2 1 It helped me with WA#21 Yep. For understanding why, lets consider: 1 7 3 2 1 4 4 5 They should be 7 numbers in the list! This test is something like this 2 2 1 2 1 2 1 2 Correct answer is YES Thank. This test help me to get AC Thank you very much,but now I've WA#33. Thank you!!! Thanks for test, i got AC Thanks a loooooooooooooooot! I am get WA on test 4. 33 .#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#. ................................# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# ##.#.#.#.#.#.#.#.#.#.#.#.#.#.#... ...............................## #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# #..#.#.#.#.#.#.#.#.#.#.#.#.#.#... ................................# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# ##.#.#.#.#.#.#.#.#.#.#.#.#.#.#... ...............................## #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# #..#.#.#.#.#.#.#.#.#.#.#.#.#.#... ................................# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# ##.#.#.#.#.#.#.#.#.#.#.#.#.#.###. ................................# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# #..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#. ................................# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# ##.#.#.#.#.#.#.#.#.#.#.#.#.#.#... ...............................## #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# #..#.#.#.#.#.#.#.#.#.#.#.#.#.#... ...............................## #.##.#.#.#.#.#.#.#.#.#.#.#.#.#... ................................# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# ##.#.#.#.#.#.#.#.#.#.#.#.#.#.#... ...............................## #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.... answer: 12384 check other tests at timustests.lx.ro 15: #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# 16: ##.#.#.#.#.#.#.#.#.#.#.#.#.#.###. 第15,16行之间不能连通! I am get WA on test 4 too! test 4 is wrong! 我知道TEST 4怎么WA的了! 有几点要归纳出来: 1: ural 有保留字: Following words are reserved. For Pascal: as class dispose except exit exports false finalization finally initialization is library new on property raise true try 我就使用了"try"这个保留字,结果就编译错误了。 2: 第四个数据的底15,16行不能连通! 所以:要从点(1,1)与点(N,N)分别搜索!(我是广搜) 如果只从点(1,1)开始搜,结果为:5760。 如果只从点(N,N)开始搜,结果为:6624。 两者之和正好是正确答案:12384 ! 希望我写的这些对你有用! IMS:WITHOUT WAX CS,HN,CHINA 2006,07,02 23:55
Thank you very much!You are so clever! thanks a lot!!!!!!!!!!!!!!!! :) you are so clever ! Thanks very much ! 可以中文??? 上面的几位聪明的中国大牛同胞,看没看见下面的Rules?明确写着“Messages should be written in English.(消息必须用英文写)”,请遵守规则,谢谢。 ------- To my clever Chinese friends above, didb't you see the Rules below? It says clearly that "Messages should be written in English." Please obey that. Thanks. You also used Chinese. Hah, i guessed myself that labyrinth can have no way from entrance to exit ) the thing is, there doesn't have to be a path from 1,1 to n,n, so you have to check both sides. i got WA at test 4 ,too! thank you!! why cant't discussion be written in chinese or russia?? # Messages should NOT contain source code (especially correct solutions). why?? i think source code indeed may cause cheat,but someone who always gets WA really need them to improve Edited by author 28.03.2008 06:14 Edited by author 28.03.2008 06:15 Good Point~ Thankx The reanson why Test#4 is valid is we can enter upper left as well as lower right. the thing is, there doesn't have to be a path from 1,1 to n,n, so you have to check both sides. Edited by author 13.08.2009 08:22Simple test for those who had WA #4: 3 ..# .#. #.. Answer is 108. Thanks! I got WA in test 4 too. Need help. Stuck for serval weeks! What is wa3 like? What is wa6 like? Store a sorted array [L...R] in each vertex of your ST, corresponding to [L;R]. Hey! Do you mind explaining the Segment tree approach a little bit more? I still couldn't understand Hi It is frequently called merge sort tree So there is an array TRANSPORTED[i] If we have want to find some value in interval of array cells from i=l to i=r We can do binary search in sorted sequence TRANSPORTED[l], TRANSPORTED[l+1],... TRANSPORTED [r-1], TRANSPORTED[r] In merge sort tree We have some sorted subsequences precalculated It is possible to represent any subsequence [l..r] as union of O(log(n)) such precalculated subsequences Скажите, пожалуйста, как можно на Вашем сайте создать свою "олимпиаду", турнир по программированию. Please Help and give me some tests! Never mind got it. The case is like this 10 <<<<><>>>> I just forgot to count the '>' that can never be used for swapping. Edited by author 01.11.2017 20:58 If in the line "outputon", this does not mean that you need to put "out" and "puton", since sometimes you can put "output" and "one". Сheck out this test: 1 outputone Answer : "YES" Perhaps this will help you. Edited by author 01.11.2017 18:28 Edited by author 01.11.2017 18:29 |
|