| Show all threads Hide all threads Show all messages Hide all messages |
| What is your idea of solution? | Vedernikoff Sergey (HSE: EconomicsForever!) | 1658. Sum of Digits | 23 Jul 2026 11:12 | 4 |
Mine quite straightforward realization works about 1 sec. and uses almost 60 megabytes of memory. Please, give an idea how to solve it more quickly... Edited by author 17.03.2010 14:10 Struggled with WA2/WA4 for a lot of submits. Tricks are tracking min-length and even then getting least possible value can be tricky. My solution is DP(900*8100)*9 to get minimal length. Then greedy BACKtracking from higher to lower using least possible digit (so you get as many '1' as possible, then as many '2' and so on) over edges that follow minimal length path. As for memory - two arrays of uint8_t. That's 14Mb. You can also sacrifice backtracking array, and perform it on the fly during generating output, would be bigger runtime, but half the memory. |
| at last i solved it | Rustam | 1658. Sum of Digits | 23 Jul 2026 10:23 | 2 |
i have +27 submites on it just because i forgot tests like that: 1 808 6464("No solution") Edited by author 10.10.2009 04:16 |
| Please help me.I got TLE on #4. | EllinY | 1658. Sum of Digits | 22 Oct 2024 17:33 | 1 |
I used dp[901][8101] for dynamic programming,but I got TLE.Can anyone give me some hints? Edited by author 22.10.2024 17:34 |
| Can somebody give me some hint ? | Crusader | 1658. Sum of Digits | 4 Jul 2024 09:25 | 12 |
can you tell me for detail ? I think it's a search problem, but I got wrong . I think it's a search problem, but I got wrong . Dynamic programming, I just solve it I used DP,but I got TLE.Can you give me some details? Many thanks!! Use DP[901][8101],and the time is 900*8100*9,then you will not get TLE again. Edited by author 04.11.2008 14:27 I still got TLE,may i have a look at your code? my email address is:xiongsenlin2006@126.com. Thank you !! Edited by author 04.11.2008 16:22 Edited by author 04.11.2008 16:22 My code wrong at test #2. Can anybody now what test 2 is? Thanks Maybe you output answers with more that 100 digits... I know why i got TLE,I should have computed all the answers preivously. but there are 1e4 test cases. |
| Some special test pls | Hemaeg | 1658. Sum of Digits | 8 Jul 2019 14:23 | 6 |
I have try many of my tests, but I don't know what is wrong in my code. What is test #2, please? Try this one: INPUT 10 1 1 10 100 200 400 900 8100 45 285 456 2119 456 2120 456 3456 456 4080 456 4081 OUTPUT 1 No solution 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 14667777 No solution 1334444444444444444444444444444444444445555555555555555555555555555555555555555555555555555555555555 2677777777777777777777777788888888888888888888888888888888888 888999999999999999999999999999999999999999999999999 No solution Thank you for your test data! WA2 Ilya 8 Jul 2019 14:23 Thks you bruh. ths s1 and s2 hack me ->(456 2120) Me too. I try the Special test but it's wrong #2 test still. The #2 test is 100 100 ,or others which the length is 100. |
| tests | Piratek-(akaDK) | 1658. Sum of Digits | 23 Dec 2018 14:41 | 5 |
tests Piratek-(akaDK) 2 Nov 2008 01:24 1 1 1 2 2 11 2 4 2 3 3 111 3 5 12 3 9 3 4 4 1111 4 6 112 4 8 22 4 10 13 4 16 4 5 5 11111 5 7 1112 5 9 122 5 11 113 5 13 23 5 17 14 5 25 5 6 6 111111 6 8 11112 6 10 1122 6 12 222 6 14 123 6 18 33 6 20 24 6 26 15 6 36 6 Edited by author 07.04.2013 15:09 |
| WA2 please help | Ghiorghiu Ioan-Viorel | 1658. Sum of Digits | 25 Dec 2017 04:15 | 2 |
I keep getting WA2, but none of the threads posted here seem to help me: every example i found worked on my program, and i just can't see what's wrong with it. Can someone please tell me if they see anything that doesn't work within my program? Thank you in advance. #define DM 8101 #define DN 901 #include <iostream> #include <set> #include <queue> using namespace std; int n, v, vp, s, sp, cf[DN][DM], dp[DN][DM]; multiset <int> ord;//ordering the elements queue <int> q;//rebuild void formare(int nrc, int car, int sum, int ptr)//no of digits, digit, sum, sumof squares { if (nrc > 100 || (cf[sum][ptr] && cf[sum][ptr] <= nrc)) return; cf[sum][ptr] = nrc; dp[sum][ptr] = car; for (int i = 9; i >= 1; --i) formare(nrc + 1, i, sum + i, ptr + i*i); } void realc(int s, int sp) { if (!s || !sp || !dp[s][sp]) return; q.push(dp[s][sp]); v+=dp[s][sp]; vp+=dp[s][sp]*dp[s][sp]; realc(s - dp[s][sp], sp - dp[s][sp]*dp[s][sp]); } int main() { cin >> n; for (int i = 9; i >= 1; --i) formare(1, i, i, i*i); cf[0][0] = 1; dp[0][0] = 0; while (n--) { cin >> s >> sp; if (s > 900 || sp > 8100) cout << "No solution\n"; else if (s == 0 && sp == 0) cout << "0\n"; else { realc(s, sp); if (q.size() <= 100) { while (!q.empty()) { if (v == s && vp == sp) ord.insert(q.front()); q.pop(); } for (auto i:ord) cout << i; ord.clear(); if (v != s || vp != sp) cout << "No solution"; cout << '\n'; } else { cout << "No solution\n"; while (!q.empty()) q.pop(); } } v = vp = 0; } return 0; } Nevermind, apparently I was calculating the number the wrong way, I found the mistake. |
| WA 1 | Raman Gupta | 1658. Sum of Digits | 18 Jul 2017 18:40 | 4 |
WA 1 Raman Gupta 3 Dec 2012 19:49 All the test cases given in this forum are working.But giving WA 1 my code is: #include <stdio.h> #include <string.h> int len[910][8110]; int dig[910][8110]; int num[110]; int main(){ int t,s1,s2,k,pt,i,j,l,temp; memset(len,0,sizeof(len)); for(i=1;i<=900;i++){ for(j=1;j<=8100;j++){ for(k=1;k<=9;k++){ if((i-k)<0||(j-k*k)<0) break; else if((i-k)==0&&(j-k*k)==0){ len[i][j] = 1; dig[i][j] = k; } else if(len[i-k][j-k*k]>0){ if(len[i-k][j-k*k]+1<len[i][j]||len[i][j]==0){ len[i][j] = len[i-k][j-k*k]+1; dig[i][j] = k; } } else continue; } } } scanf("%d",&t); while(t--){ scanf("%d %d",&s1,&s2); pt = 0; if(len[s1][s2]==0||len[s1][s2]>100) printf("No Solution"); else{ i=s1; j=s2; while((len[i][j]>=1)&&i>=1&&j>=1){ l = dig[i][j]; num[pt++] = l; i = i-l; l = l*l; j-=l; } for(i=0;i<pt;i++){ for(j=i+1;j<pt;j++){ if(num[i]>num[j]){ temp=num[i]; num[i]=num[j]; num[j] = temp; } } } for(i=0;i<pt;i++) printf("%d",num[i]); } printf("\n"); } return 0; } Your mistake is here: if(len[i-k][j-k*k]+1<len[i][j]||len[i][j]==0){ len[i][j] = len[i-k][j-k*k]+1; dig[i][j] = k; } length might be the same but the value might be smaller. You just check the length. I am able to see experimentally that length really might be the same while the values differ I can't understand why it so I feel that it can't be truth "S" in "Solution" shouldn't be capital :P |
| RE4(Access Violation) | Vova | 1658. Sum of Digits | 9 May 2017 13:10 | 3 |
WTF?! I have RE4(Access Violation). I don't understand why? You only need DP[8100][900] or DP[900][8100] instead of DP[10000][10000] |
| For all those failing test 2 | Grape | 1658. Sum of Digits | 26 Aug 2016 07:22 | 1 |
Samples: 1 201 405 Should be 99(2) + (3) 1 301 907 Should be 99(3) + (4) 1 448 2824 Should output something large, but the solution definitely exists :) Edited by author 26.08.2016 07:23 |
| WA 2 | Vova | 1658. Sum of Digits | 28 Feb 2016 07:37 | 2 |
WA 2 Vova 6 Jan 2016 18:43 I have WA 2. I don't understand why? Give me some tests please, which will help me understand my mistake. Thank you. Re: WA 2 Drunken Statue 28 Feb 2016 07:37 Hint: read requirements in careful way Closely look at _output_ requirements |
| Help WA4 | sherbina_evgeniy | 1658. Sum of Digits | 30 Oct 2015 15:12 | 3 |
Help WA4 sherbina_evgeniy 4 May 2015 02:56 I have WA4. I don't understand why? Give me some tests please, which will help me understand my mistake. Thank you. Please,I wa 4 ,too.Thanks. Me too!Please!Thx! Please,I wa 4 ,too.Thanks. |
| Why wa 4? | bayram | 1658. Sum of Digits | 4 Jun 2015 14:37 | 3 |
Make sure s1 and s2 are within the limits of the problem. ER, thank you! Thanks to author for challenging task. |
| If you have TLE in java | Cebotari Vladislav | 1658. Sum of Digits | 15 May 2015 21:40 | 1 |
Instead of doing a lot of System.out.print, write all chars in a StringBuilder, and then print the StringBuilder once in the end. |
| If you have WA2 | hliu20 | 1658. Sum of Digits | 11 Jun 2014 02:51 | 2 |
if the number of digits is greater than 100, should print "No solution" Thanks! Saved me a lot of time! :) |
| 0.14, 16914 kb :) | Vit Demidenko | 1658. Sum of Digits | 23 Oct 2013 16:57 | 2 |
3 arrays [8100*900] of byte O<8100*900*9, DP Edited by author 10.09.2009 18:56 Only one with 0.25 time and 7K memory. Isnt your time complexity O(900*8100*9)? |
| MLE4 | ONU_Antananarivu | 1658. Sum of Digits | 23 Oct 2013 16:56 | 3 |
MLE4 ONU_Antananarivu 11 Sep 2011 13:41 Why when I allocated staticly globaly memory like this char a[10005][10005] = {0}; char d[10005][10005] = {0}; I got MLE 4, but not MLE 1? You can used only: char a[901][8101]; char d[901][8101]; Because 9....9 (100 times) S = 900 and S^2 = 8100 Re: MLE4 ძამაანთ [Tbilisi SU] 23 Oct 2013 16:56 Maybe because of the compiler's optimizations |
| No subject | Azat Yusupov(TUIT Urgench) | 1658. Sum of Digits | 8 Nov 2011 13:11 | 1 |
No subject Azat Yusupov(TUIT Urgench) 8 Nov 2011 13:11 Edited by author 29.12.2011 01:34 |
| Please help me | sign_in158 | 1658. Sum of Digits | 13 Oct 2011 19:46 | 1 |
Can anyone tell me how to use dynamic programming in this problem |
| Guy could you please give me some hint? | Vasiliy | 1658. Sum of Digits | 24 Oct 2010 19:29 | 1 |
Or could you send me your code to investigate? kobchik83@list.ru |