| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| It's simple | Cat36 | 1003. Чётность | 17 апр 2021 15:55 | 15 |
//main logic #include <stdio.h> #include <map> #include <iostream> using namespace std; map<int, bool> exist; map<int, bool> odd; map<int, int> prev; bool add(int a, int b, bool c){//b>=a; if (!exist[b]){ exist[b] = true; odd[b] = c; prev[b] = a; return true; }; int i = prev[b]; if(i==a) return (odd[b]==c); if(i<a) return add(i,a-1, (c!=odd[b])); return add(a,i-1, (c!=odd[b])); }; Thank you very much, at least I solved it! Nice problem! thank you! i study very from you Thanks! nice idea ;) I've got AC thank you very much!!!) Edited by author 01.11.2011 17:53 100 5 5 6 odd 7 8 odd 1 6 even 1 4 odd 7 8 even why result is 3 and not 4? because 1 1 = 0 but 0 0 not 1 the input format is verrrry misleading, i have lost 2 hours of my live because of it. #include <stdio.h> #include <map> #include <iostream> #include <string> using namespace std; map<int, bool> exist; map<int, bool> odd; map<int, int> previous; bool add(int a, int b, bool c){//b>=a; if (!exist[b]){ exist[b] = true; odd[b] = c; previous[b] = a; return true; }; int i = previous[b]; if(i==a) return (odd[b]==c); if(i<a) return add(i,a-1, (c!=odd[b])); return add(a,i-1, (c!=odd[b])); }; int main(int argc, char * argv[]) { while (1) { exist.clear(); odd.clear(); previous.clear(); int numbers = 0; cin >> numbers; if (numbers==-1) break; int questions = 0; cin >> questions; bool flag = false; for (int i = 0; i<questions; i++) { int a = 0; cin >> a; int b = 0; cin >> b; string tmp; cin >> tmp; bool parity = false; if (tmp=="even") { parity = true; } if ((add(a,b,parity)==false)&&(flag==false)) { cout << i; flag=true; } } if (flag==false) { cout << questions; } } return 0; } What wrong? I got wa at 1 test. Then run it in the debug mode and you'll figure it out. change bool parity = false; if (tmp=="even") { parity = true; } to bool parity = true; if (tmp=="even") { parity = false; } and then break after flag=true; Edited by author 21.03.2012 22:25 Edited by author 21.03.2012 22:25{ 100 5 5 6 odd 7 8 odd 1 6 even 1 4 odd 7 8 even why result is 3 and not 4? } I think the answer is 4, because [1,4] is odd and [5,6] is odd and [1,4],[5,6] are continuous then the answer isn't 3, but it is 4. Edited by author 02.05.2012 15:37 Edited by author 02.05.2012 15:40 Edited by author 02.05.2012 15:40 Good programing skills!! Thanks~ :0 this approach is out of my mind, great work!! |
| looks ok but wrong answer,why? | meherin | 2012. Про Гришу Н. | 16 апр 2021 17:55 | 2 |
#include<stdio.h> int main() {int f,left,time; scanf("%d",&f); left=12-f; time=left*45; if(time<=240){ printf("Yes");} else{printf("No"):} return 0;} else{printf("No"):} ; not : xd |
| If You have WA 13 | 107th | 1570. Ужин на 45 этаже | 16 апр 2021 13:44 | 3 |
look at overflow!!! in test 13 there are meny than 32 different dishes!!! my bug was: int h = j; ... d[i] |= (1 << h); change it to __int64 h = __int64(j); ... d[i] |= (__int64(1) << h); Edited by author 26.08.2008 17:18 Limit for dishes is 100. Why __int64 (64 bit) should be better than int (32 bit)? In both cases you need an array, don't you? |
| why wa on test 13/?? | leehark | 1570. Ужин на 45 этаже | 15 апр 2021 15:33 | 3 |
CAN SOME ONE GIVE ME SOME TEST? MY GMAIL: LIHE21327@GMAIL.COM First, DP needs to be 2D. Values array can be 1D, but backtracking info should be 2D. At least I couldn't make it 1D. And even after making parental state indication 2D I still had bugs in that back-traversal :) about wa 13 i am pretty sure its a problem with backtracking. |
| hints | Abid29 | 1965. Саженцы груши | 13 апр 2021 18:18 | 2 |
hints Abid29 13 апр 2021 18:16 its a greedy+dp according to me you should analyze the four scenario like 1. two increasing sequence :
take two array . two array initially have only one value zero. then iterate over 2nd to nth element. if element > 1st and 2nd arrays last element then, 1st sequence last element > 2nd arrays last element then: (add element to the 1st array) otherwise (add element to the 1st array) otherwise add it to the array whose last element < element
(this is optimal ). 2. two decreasing sequence: approach greedily like 1st one 3. one increasing and one decreasing(1st element included in the increasing array):(try yourself) 4. one increasing and one decreasing(1st element included in the decreasing array):(try yourself) for 3rd and 4th criteria , think greedily also. my solution is 0.14sec if you are better plz email me s-2017915104@isrt.du.ac.bd |
| WA2 Hint | Sukarna Paul | 1131. Копирование | 13 апр 2021 17:51 | 1 |
The program is already installed in one computer. Now, we need to install it in (N-1) computers. |
| In fact it's doubled Fibonacci sequence. Easy game. | Vyacheslav Glushkov | 1225. Флаги | 11 апр 2021 19:39 | 1 |
|
| AC tests | Gleb Dubosarskii | 1577. Электронная почта | 11 апр 2021 10:34 | 2 |
AC tests Gleb Dubosarskii 24 апр 2017 01:18 abc cba 6 aba bab 2 abcabc cba 5 abcbaabdca abcada 1 abcabbaca abcabbc 1 thnx a lot for your tests |
| it takes my days | Abid29 | 1696. Зарплата для роботов | 10 апр 2021 22:04 | 1 |
you can easily find the solution with O(nk^3) but it will give u tle after optimization with cumulative sum array it will be O(nk^2) |
| Right algo but too slow | Bekmuhamet | 1017. Лестницы | 9 апр 2021 19:01 | 2 |
import java.util.Scanner; public class Staircases { public static void main(String... args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); System.out.println(find_Q(N, N)); }
static int find_Q(int X, int Y) { int U = X-1; if(Y<X) { U = Y; if(Y == 0 || Y ==1) return 1; } if(Y<=1) return 0; int A = 0; for(int i = U; i > 0; i--) A += find_Q(i, Y-i); return A; } } Use bottom-up approach, calling function and return rakes huge amount of time |
| This task is driving me crazy | Zergatul | 1798. Огненный круг. Версия 2 | 8 апр 2021 01:51 | 2 |
I've implemented several approaches, ones calculate 1/4 of circle, another ones calculate 1/8 of circle. All of them works fine for R < 60000000. With R > 60millions there is a chance (and it increases with bigger R) 2 approaches can give different results. They use the same calculations (sqrt, ceiling). I also tried to implement 1/8 without float point numbers, by integers only. Same result with same difference. Maybe these "magic" numbers can help someone r: 67250001 correct: 14208049816923164 diff: 12 r: 67250051 correct: 14208070944129524 diff: 4 r: 67250211 correct: 14208138551359320 diff: 4 r: 67250249 correct: 14208154608083608 diff: 8 r: 67250321 correct: 14208185031387396 diff: 16 r: 67250433 correct: 14208232356606236 diff: 4 r: 67250449 correct: 14208239117361224 diff: 4 r: 67250505 correct: 14208262780007696 diff: 4 r: 67250601 correct: 14208303344588340 diff: 8 r: 67250697 correct: 14208343909213316 diff: 4 r: 67250769 correct: 14208374332717888 diff: 4 r: 67250825 correct: 14208397995480888 diff: 4 r: 67250835 correct: 14208402220968636 diff: 4 r: 67251315 correct: 14208605045441340 diff: 8 r: 67251347 correct: 14208618567139620 diff: 12 r: 67251457 correct: 14208665047975948 diff: 4 Edited by author 07.04.2021 02:35 Forget about what I said earlier. It is always good idea to return to the problem with fresh mind :) It turned out my correct solution was actually incorrect, and my incorrect solutions were correct. If you are using sqrt and ceil, try to calculate ceil(sqrt(2 * 63611501 * 67250001 - 63611501 * 63611501)), and you will get wrong result I was able to get AC C# solution with 467286474 int64 multiplications for R=10^9, no divisions, and no floating point usage. Edited by author 08.04.2021 01:53 Edited by author 08.04.2021 01:53 |
| I got WA in test 1 | samariddin | 1112. Покрытие | 7 апр 2021 23:29 | 1 |
I got WA in first test. I checked my program using a lot of compiler and in first test my program outputs is correct. my code id:9308865 |
| Really Nice Problem!!!!!!!!!! | Sevenk | 1690. Армия магов | 7 апр 2021 21:02 | 3 |
+1 Just use Dirichlet's principle. |
| math sol needed | Abid29 | 1276. Train | 7 апр 2021 13:25 | 1 |
AC in 0.015 sec with dp if u r better with math plz reply Edited by author 07.04.2021 13:27 Edited by author 07.04.2021 13:27 Edited by author 07.04.2021 13:27 |
| hints | Abid29 | 1276. Train | 7 апр 2021 13:24 | 1 |
hints Abid29 7 апр 2021 13:24 AA=0,AB=1,BA=2,BB=3 cnt[0]=no. of AA,cnt[1]=no. of AB........... int sz=2; if(last letter==A) szvalue=0; if(last letter==B) szvalue=2; define DP[cnt[0]+2][cnt[1]+2][cnt[2]+2][cnt[3]+2][sz]; dp 1,0,0,0,0=1; //for AA dp 0,1,0,0,1=1; //for AB |
| WA4 - Memory limit exceeded HELP ME | supanat | 1048. Сверхдлинные суммы | 5 апр 2021 19:15 | 3 |
Edited by author 05.05.2016 19:23 I think string is: result = str(b) +result During this operation: - new string with size = result.size+1 created; - b contents copied to new string I am not sure about memory but it must lead to TLE. You know your n1, n2, result strings have known size = n. You should rather use efficient byte arrays of size n to store n1, n2, result contents Edited by author 28.04.2016 13:22 if You get TLE verdict, U can try to use short instead of int |
| for wa#10 | vahan | 1726. Кто ходит в гости… | 5 апр 2021 18:00 | 6 |
I had int n,i; and I had wa #10, then I changed them to long long and got ac, but I can't understand why I got wa10 with int n,i; where i and n can't exceed 10^6. It's obviously a mistake in task's text. Program won't be accepted until it will work with n=10e6. thanks for your hint, helped me to get accepted verdict When you divide at the end by n*(n - 1) it gets overflow so you need to have type long long Edited by author 31.10.2020 16:46 Edited by author 31.10.2020 16:46 You need long long n. Because you divide at the end by n*(n - 1),n*(n-1) is overflow. |
| The problem is overrated | [ЛЕСТЕХ] UstinovG`~ | 1798. Огненный круг. Версия 2 | 5 апр 2021 11:54 | 1 |
My algorithm is O(R) and i have AC |
| WA #1.HHHHEEELLP!!! | Accepted | 1061. Диспетчер буферов | 4 апр 2021 12:25 | 2 |
I got WA at #1 and I use line tree. Now I've accepted! Edited by author 07.03.2013 19:40 Try to change compiler to Microsoft Studio. Worked for me |
| time limit test 5 | Alexandr | 1002. Телефонные номера | 3 апр 2021 21:45 | 6 |
Stacked at this point too. Found that following example crashes my structure for a looooong time to think: 2222223222222222322222222222322222222232222222222232222222223222222222223222222222322222 5 a aa afa aaaa aafaa answer should be like "aaaa aafaa aaaa aafaa etc..." Thanks for this example. My backtracking solution also is way too slow. Yes. A very nice benchmark. Edited by author 03.05.2015 16:52 Edited by author 03.05.2015 16:53 aaaa aafaa aa aaaa afa aaaa aaaa aafaa aa aaaa afa aaaa aaaa aafaa aa aaaa afa aaaa aaaa aafaa aa aaaa afa aaaa Very nice test, I understand, because my program is too slowly. |