| Show all threads Hide all threads Show all messages Hide all messages |
| What method I have to use? | Neo Nomaly | 1448. Lighting in Hogwarts | 13 Aug 2017 23:23 | 3 |
The only method I used to solve it was the intuition. I hope anyone who knows a proof of any solution (I think there are many) will expain it. Пожалуйста, не сдавайте задачу, не понимая своё решение!!! Это хорошая математическая задача из темы на конструктив. Во-первых, покажем, что решение всегда существует. Для k=1 утверждение справедливо. Пусть уже построена последовательность s1...sk, удовлетворяющая условию задачи. Пусть cij=кол-во 1 на [i,j]. Покажем, что можно добавить 0 или 1 в конец, чтобы полученная последовательность также была решением. Предположим противное: при добавлении 0 есть подотрезок [i,k+1], где cik>(k-i+2)b/100+2 (1) или cik<(k-i+2)b/100-2 (2) и при добавлении 1 есть подотрезок [j,k+1], где cjk>(k-j+2)b/100+1 (3) или cjk<(k-j+2)b/100-3 (4). Заметим, что (1) и (4) невозможны (по индукции |cik-(k-i+1)b/100|<=2 => cik<=(k-i+1)b/100+2 и |cjk-(k-j+1)b/100|<=2 => cjk>=(k-j+1)b/100-2). Итого получаем (2) и (3) одновременно: cik<(k-i+2)b/100-2, cjk>(k-j+2)b/100+1 => cjk>cik => j<i. Рассмотрим отрезок [j,i-1]. По индукции cj,i-1=cjk-cik удовлетворяет условию |(cjk-cik)-(i-j)b/100|<=2 => cjk<=cik+(i-j)b/100+2<(k-i+2)b/100+(i-j)b/100=(k-j+2)b/100. => cjk<(k-j+2)b/100. С другой стороны, выполнено (3)-противоречие => 0 или 1 даёт решение длины к+1. Как сконструировать решение? Из док-ва видно, в каких местах возникают проблемы. Когда можно добавить 0 (если нельзя => нужно добавить 1-это даст решение по док-ву)? 0 можно добавить <=> для 1<=i<=k выполнено (k-i+2)b/100-2<=cik<=(k-i+2)b/100+2. Второе неравенство выполнено (т.к. cik<=(k-i+1)b/100+2). Поэтому нужно (k-i+2)b/100-2<=cik. Когда это условие нарушается? Оно нарушается <=> существует такое 1<=i<=k, что cik<(k-i+2)b/100-2 <=> cik<(-b/100)i+(2kb/100-2).Заметим что cik неубывает, а (-b/100)i+(2kb/100-2) строго убывает => нарушение происходит <=> i=1 <=> c1k<-b/100+2kb-2=kb/100-2 <=> 100*c1k<kb-200. В этом случае 0 брать нельзя. Edited by author 13.08.2017 23:28 |
| if you have wa#7 | Baurzhan | 1713. Key Substrings | 13 Aug 2017 20:07 | 2 |
try this test 2 abab baa answer: ab aa |
| Time limit exit! | Ayaz | 1086. Cryptography | 13 Aug 2017 12:47 | 1 |
I have used sieve theorem but i am still getting TLE! i need my code optimization .here is my code: #include<iostream> #include<cmath> using namespace std; #define TOTAL 163841 int main() { int ara[TOTAL]; for(int i=2; i<TOTAL; i++) { ara[i]=1; } int root = sqrt(TOTAL); for(int i=2; i<=root;i++) { for(int j=2; i*j<=TOTAL; j++) \\ Using sieve theorem { ara[i*j]=0; } } int T; int n; cin >> T; int r,k; for(int l=1; l<=T; l++) { cin >> n; if(n<=15000) { int ara2[n]; for(k=2,r=1;r<=n;k++) { if(ara[k]==1) { ara2[r]=k; \\ copying the prime numbers to the ara2[] r++; } } cout << ara2[n] << "\n"; // cout the last num of ara2[] } } return 0; } Edited by author 13.08.2017 12:49 |
| How many tests are there, lol? | Mahilewets Nikita [BSUIR] | 2011. Long Statement | 12 Aug 2017 16:21 | 1 |
There are at LEAST, 70 tests. |
| Stupid hint | Felix_Mate | 2059. Not common palindromes | 12 Aug 2017 01:51 | 1 |
If you got TL you can try send same code and to get AC. When I delete 2 string (they are comments) i got AC. |
| weak tests | falicos | 1592. Chinese Watches | 11 Aug 2017 21:18 | 1 |
my program as many others in net got AC but failed on test 3 1:00:00 12:59:58 12:59:59 Correct answer is 1:00:00 but not 13:00:00. |
| #test 11 | liudy | 1781. Clean Code | 11 Aug 2017 16:43 | 1 |
Can someone give me some hints about what #test 11 is? |
| WA 7, WA 8 | 💻Evgeny Nemtsev [UrFU FT-17]'` | 1608. Lucky Tickets 2008 | 10 Aug 2017 22:53 | 1 |
WA 7, WA 8 💻Evgeny Nemtsev [UrFU FT-17]'` 10 Aug 2017 22:53 |
| How to solve this problem without long arithmetic? | Felix_Mate | 1103. Pencils and Circles | 10 Aug 2017 16:38 | 1 |
If i use double -> big error If i use long long -> overflow now i got Runtime error on java. Where I am wrong? I think my function Less is bad but I can't find mistake. My code: import java.math.*; import java.util.*; public class BigNumbers { final int tmax=100; MathContext mc = new MathContext(tmax);
final int nmax=5005;
static int Pox[], Poy[], id[]; static BigDecimal Px[], Py[]; static int n, left;
public static boolean Less(BigDecimal x1, BigDecimal y1, BigDecimal x2, BigDecimal y2) { return (y1.compareTo(BigDecimal.ZERO)!=-1) && (y2.compareTo(BigDecimal.ZERO)==1) && ((y1.multiply(x2)).compareTo(x1.multiply(y2))==-1) || (y1.compareTo(BigDecimal.ZERO)==-1) && ((y2.compareTo(BigDecimal.ZERO)!=-1)) || ((x1.multiply(y2)).compareTo(x2.multiply(y1))==1); }
public static BigDecimal modul2(BigDecimal x, BigDecimal y) { return (x.multiply(x)).add(y.multiply(y)); }
public static void QSort(int L, int R) { int m=(L+R)/2; int i=L; int j=R;
while(i<=j) { while(Less(Px[i],Py[i],Px[m],Py[m])) i++; while(!Less(Px[j],Py[j],Px[m],Py[m]) && j!=m) j--; if(i<=j) { BigDecimal Y=Px[i]; Px[i]=Px[j]; Px[j]=Y; Y=Py[i]; Py[i]=Py[j]; Py[j]=Y; int y=id[i]; id[i]=id[j]; id[j]=y; i++; j--; } } if(L<j) QSort(L, j); if(i<R) QSort(i, R); }
public static void main(String args[]) { Scanner sc=new Scanner(System.in); n=sc.nextInt();
Pox=new int[n+1]; Poy=new int[n+1]; id=new int[n+1]; Px=new BigDecimal[n+1]; Py=new BigDecimal[n+1];
for(int i=1;i<=n;i++) { int x, y; x=sc.nextInt(); y=sc.nextInt(); Pox[i]=x; Poy[i]=y; }
System.out.println(Pox[1]+" "+Poy[1]);
for(int i=1;i<=n-1;i++) { BigDecimal x=BigDecimal.valueOf(Pox[i+1]-Pox[1]); BigDecimal y=BigDecimal.valueOf(Poy[i+1]-Poy[1]); Px[i]=x.divide(modul2(x,y)); Py[i]=y.divide(modul2(x,y)); id[i]=i+1; }
left=1; for(int i=2;i<=n-1;i++) if(Px[left].compareTo(Px[i])==1 || Px[left].compareTo(Px[i])==0 && Py[left].compareTo(Py[i])==1) left=i;
System.out.println(Pox[id[left]]+" "+Poy[id[left]]);
for(int i=1;i<=n-1;i++) { Px[i]=Px[i].subtract(Px[left]); Py[i]=Py[i].subtract(Py[left]); }
for(int i=left;i<=n-2;i++) { Px[i]=Px[i+1]; Py[i]=Py[i+1]; }
QSort(1,n-2); System.out.print(Pox[id[(n-1)/2]]+" "+Poy[id[(n-1)/2]]); } } |
| Try to consider vertices with the same distance to f from s | Mahilewets Nikita [BSUIR] | 2034. Caravans | 10 Aug 2017 10:54 | 1 |
|
| Phobia | retNAN | 1951. Complex Root | 8 Aug 2017 00:35 | 4 |
Phobia retNAN 15 Jun 2013 20:02 Two Complex numbers are equivalent if they have the same moduli and there argument differ by a multiple of 2pi.how best can you solve this without encountering irrational numbers especially when you are dealing with nth root. Edited by author 15.06.2013 20:16 Yes, there's exists solution only in integer numbers for this problem. Edited by author 08.07.2018 15:42 |
| .001 AC solution without memoization . | Rafat Islam | 1044. Lucky Tickets. Easy! | 6 Aug 2017 22:17 | 2 |
#include <bits/stdc++.h> using namespace std ; #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define mem(x,val) memset((x),(val),sizeof(x)) #define all(x) x.begin(),x.end() #define pb push_back #define mp make_pair #define PI acos(-1.0) const int INF = 1 << 29 ; typedef long long ll ; int N(int n , int k ) { if(n == 1) return k<10?1:0 ; int sum = 0 ; for(int i = 0 ;i<= 9 && i<=k ; i++){ sum+=N(n-1 , k-i) ; } return sum ; } int main() { int n ,sum = 0 , temp ; scanf("%d" ,&n) ; n/= 2 ;
for(int i = 0 ; i<=n*9 ;i++){ temp = N(n,i) ; sum+=(temp*temp) ; } printf("%d\n" , sum) ; return 0 ; } |
| How to achieve such an incredible speed like MrWindows' 0.4 sec? | Mahilewets | 2062. Ambitious Experiment | 6 Aug 2017 18:10 | 2 |
I have thought about something like lazy calculations model |
| Newton Raphson instead of sqrt() but getting WA on test case 2 | thanos | 1001. Reverse Root | 6 Aug 2017 10:30 | 3 |
#include<iostream> #include <iomanip> #include<vector> int main(){ long long num; std::vector<double> v; int count=0; while(std::cin>>num){ if(num==0){ v.push_back(num); } else{ int i=0; double n=num/10; while(i<10000){ n=n-(n*n-num)/(2*n); i++; } v.push_back(n); }
} for(int i=v.size()-1;i>=0;i--) std::cout<<std::fixed<<std::setprecision(4)<<v[i]<<std::endl; return 0; } Suppose you have no WA. Then you might have 15000+ square roots by 10000 iterations each (If pay attention there are maximum 256KB of numbers) TLE for sure Yup. I just realized it. But I think it converges to 4 decimal places much, much before 10000 iterations (say, like 300-400). Thanks for the help :) |
| Avoiding TL | vlyubin | 1846. GCD 2010 | 6 Aug 2017 06:31 | 4 |
I was barely able to pass the TL by using the segment tree. That part probably works OK, but what causes troubles is the way I locate the array index by given content value (i.e. we want do delete 8, so I search for 8's index and replace it with 0). For that purpose I was using map from STL and wasn't able to come up with anything better (except some hash-like storage). What did you use for that purpose or could you avoid such situation at all? Thanks. I solved by exactly the same algorithm, but got TLE 16-21. Then I just changed my cin to scanf and got AC for 0.218 Try ios::sync_with_stdio (false) . Report was it success or not. I am interested how useful is ios::sync_with_stdio(false) . Yes it does help. My solution (sqrt) was TLE 17. after this line it is AC 0.421. Just put this into main as the first line. thanks for the suggestion, I was too lazy to use scanf:) dont forget though that if you use this, then you cannot use printf and scanf in the same program with cin |
| Ambiguous problem statement (+) | Alipov Vyacheslav [Tomsk PU] | 1412. Autumn Tide | 5 Aug 2017 22:46 | 2 |
It's a complete disaster! I just don't get it. 1) Quote: "Exactly 1 mm of precipitations fall down on the pitch each minute" Another quote: "You should output the average amount of precipitations (in millimeters) falling on the pitch in a minute." So the reasonable question is: "Why the answer is just the area of the pitch without a small piece??" It shoud be less than one millimeter! Ammount of precipitations is the height of the water column that arises from the surface in a particular period of time. Hence under the umbrellas the ammount equals to zero. And according to the statement the answer is (1 - area_covered_with_umbrellas / area_of_the_pitch). 2) Quote: "All the water that has fallen on an umbrella streams down along the shortest way on the hemisphere." So what? Does it mean that the water from the umbrella falls back on the pitch without changing the answer? Or, may be, it changes somehow the ammount of precipitations in the area near the umbrella... And if the umbrella is on the border of the pitch, than what ammount of water falls outside the pitch - area of spherical sector or area of its projection or area of spherical sector minus area of the layer falling out of the pitch? BTW None of these variants didn't produce the answer given in the sample output. I'd appreciate any information you could give me to remove an ambiguity. 1)HINT: за счёт зонтов осадков может выпасть больше. 2)"Вся вода попавшая на зонт, стекает по радиусам зонта от центра к краям" и затем падает вертикально вниз. |
| attention! you must sort answer! | Felix_Mate | 1189. Pairs of Integers | 5 Aug 2017 20:58 | 1 |
I got WA4. Then i sorted answer by <length, int, int> and got AC. |
| what wrong with my code...-_- | noname | 1010. Discrete Function | 5 Aug 2017 19:28 | 2 |
[code deleted] Edited by moderator 02.01.2020 18:17 cout<<"enter a number for the lines "<<endl; Surely that is wrong |
| WA20 Resolved. The task is so easy that I have overcomplicated it and failed to solve quick | Mahilewets | 1796. Amusement Park | 2 Aug 2017 18:26 | 1 |
I was trying to remove from the set first non-zero count money unit that is NOT LESS than ticket But actually the task asks to remove just the FIRST non-zero count money unit If act according to the former strategy you will receive WA20. |
| WA4 | Ctalk3r | 1992. CVS | 2 Aug 2017 00:31 | 2 |
WA4 Ctalk3r 1 Aug 2017 15:23 #include <iostream> #include <vector> using namespace std; string per(int x) { int k(0),b(x); string m; if (x<10) {m+=char(x+'0');return m;} while(x!=0) { x=x/10; k++; } x=b; b=k; string s; while(k>0) { s+=char((x%10)+'0'); x=(x-x%10)/10; k--; } for(int i=0;i<b;i++) m+=s[b-i-1]; return m; } int main() { int n,m,i,j,p,t(1); char s[80]; string Y; vector<int> v; vector<int> w; v.reserve(1); w.reserve(1); scanf("%d",&n); scanf("%d",&m); for(int d=0;d<n;d++) { scanf("%s",s); if(s[0]=='l') { scanf("%d%d",&i,&j); if(j>m) continue; if(t<i) continue; v.push_back(j);w.push_back(i); p=w.size(); for(int x=0;x<p;x++) if(w[x]==i && v[x]<0) {v.erase(v.begin()+x);w.erase(w.begin()+x);} } if(s[0]=='r'&& s[1]=='o') { scanf("%d",&i); p=w.size()-1; while(v[p]<0 || w[p]!=i) p--; v[p]-=1000000;} if(s[0]=='c'&& s[1]=='h') { scanf("%d",&i); if(w.size()>0) { for(int x=w.size()-1;x>=0;x--) if(w[x]==i && v[x]>0) {Y+=per(v[x]);if(d!=n-1)Y+="\n";break;} else if (x==0) {Y+="basic";if(d!=n-1)Y+="\n";} } else {Y+="basic";if(d!=n-1) Y+="\n";} } if(s[0]=='r'&& s[1]=='e') { scanf("%d",&i); p=0; while(v[p]>0 || w[p]!=i) { p++; if(p>w.size()-1) break; } if(p>=0) v[p]+=1000000; } if(s[0]=='c'&& s[1]=='l') { if(t<i) continue; t++; scanf("%d",&i); p=w.size(); for(int x=0;x<p;x++) if(w[x]==i) {v.push_back(v[x]);w.push_back(t);} } } cout<<Y; } I can't make up any new tests. Everything, I tried, works. If you have some ideas, please, help Edited by author 01.08.2017 15:26 Edited by author 01.08.2017 15:28 The problem is connected with recoil |