Common BoardSo, I just wrote solution with C long double and got WA #5 (Laplacian). Then I just rewrote it in Python with decimal.py and got WA...#3! Then I started to add more precision to decimal and got TLE #3. Yeah, I use some epsilon constant and add it to determinant before convert determinant to integer and get its modulo 10**9. Lol FINALLY understand I should just made M[row] [col] =LCM Yeah! I tried this: 3 3 *** *.* *** And got zero, not one! Should correct... WA #8. I am really frustrated. http://ideone.com/7nPKN0 That time without fractions. Used decimal with 1450 digits after point. Edited by author 08.05.2017 18:47I realized I need not determinant of a whole matrix but just a minor. http://ideone.com/5H6ARHSubmitted corrected solution with Fractions. Buuut!! WA #8 still... import sys def reverse(i): if len(i) == 1: return i else: return i[len(i)-1]+reverse(i[:len(i)-1]) def getReverseLine(s): start = 0 for i in range(len(s)): if (ord(s[i]) < 123 and ord(s[i]) > 64) and (ord(s[i]) < 91 or ord(s[i]) > 96): if i == len(s)-1: if start < i: s = s.replace(s[start:i+1], reverse(s[start:i+1])) else: if start < i: s = s.replace(s[start:i], reverse(s[start:i])) start = i+1 else: start += 1 return s lines = [] while True: line = sys.stdin.read() if line == '': break lines.append(getReverseLine(line)) text = '\n'.join(lines) print text 3 6 1 2 5 7 5 2 1 4 1 4 7 4 1 5 2 3 6 5 4 2 my solution: 15 2 5 7 5 2 1 2 3 6 5 4 7 4 1 4 2 2 4 1 2 3 4 1 4 1 2 3 4 1 my solution: 4 1 2 3 4 1 4 1 1 1 1 1 1 1 1 1 1 1 1 my solution: 1 1 1 Are there any test cases for debugging? Here is my program,I have taken WA on the test of 2, I think it is correct,please tell me what is wrong,please if you can.. program fillword; var a:array[1..10] of string; b,k:array[1..100] of string; i,j,n,m,p,t:integer; ch:char; l,r:string; begin read(n,m,p); readln; for i:=1 to n do readln(a[i]); for j:=1 to p do readln(b[j]); for i:=1 to p do for j:=1 to n do if b[i]=a[j] then begin t:=t+1; k[t]:=b[i]; break; end; for i:=1 to t do begin r:=''; l:=k[i]; for ch:='A' to 'Z' do for j:=1 to m do if ch=l[j] then r:=r+ch; writeln(r); end; end. 9 years later... >for i:=1 to p do > for j:=1 to n do I suppose, it shouldn't be to p... BTW: I have used self-implemented high-precision longint to solve this problem. 1000 0 0 -1000 0 0 1000 1000 VISIBLE 1000 -0.000001 0 -1000 0 0 1000 1000 INVISIBLE 1000 0 -0.000001 -1000 0 0 1000 1000 INVISIBLE 1000 0 0.000001 -1000 0 0 1000 1000 VISIBLE 1000 -0.000001 0.000001 -1000 0 0 1000 1000 VISIBLE 1000 -1000 999.999999 -1000 0 0 1000 1000 INVISIBLE 1000 -1000 999.999999 -999.999999 0 0 1000 1000 VISIBLE -999.999999 -1000 1000 999.999999 0 0 1000 1000 VISIBLE 1 2 1 0 0 0 0 1 VISIBLE 1.000001 2 1 0 0 0 0 1 VISIBLE 0.999999 2 1 0 0 0 0 1 INVISIBLE 1000 0 1000 -0.000001 0 0 0.000001 1000 VISIBLE 1000 0 1000 -0.000002 0 0 0.000001 1000 VISIBLE 1000 0 1000 -0.000003 0 0 0.000001 1000 INVISIBLE 2 more test which help me get AC, I fails on checking that both points on 1 side of line. 40 60 59 40 50 30 90 70 VISIBLE 40 60 61 40 50 30 90 70 INVISIBLE var s: array[1..50] of string; si, i1, i, c: integer; input, output: text; begin {$IFNDEF ONLINE_JUDGE} assign(input, 'input.txt'); reset(input); assign(output, 'output.txt'); rewrite(output); {$ENDIF} while not seekeof(input) do begin inc(si); read(input, s[si]); end; c := 1; for i := 1 to si do for i1 := 1 to length(s[i]) do begin if c = 0 then s[i][i1] := lowercase(s[i][i1]); if (c = 1) and (s[i][i1] <> ' ') and (s[i][i1] <> '-') and (s[i][i1] <> ':') then c := 0; if (s[i][i1] = '?') or (s[i][i1] = '.') or (s[i][i1] = '!') then c := 1; end;
for i := 1 to si do writeln(output, s[i]); {$IFNDEF ONLINE_JUDGE} close(input); close(output); {$ENDIF} end. Maybe finite state automation. divide the matrex into three divisions >> above the diagonal >>> the diagonal>>under the diagonal simulate more than matrix for insure your answer All mentioned solutions cause TLE. I have got "accepted" on python 2.7 even with very ineffective variant, and python 3.4 always writes TLE ?????? I have same problem! This solution difficult is O(n), but i got TLE #11 [code cuted] I send this code with python 2.7 and got AC with time 0.67. lol) Edited by author 30.04.2017 12:38 Нашел ошибку. =) Edited by author 12.05.2014 09:33 То же самое у меня, WA1 и все тут, хотя у меня нормально проходило и другие тесты. Вчем была ошибка ? I have WA1 too, i cant understand why, because example from briefing was ok. Python code: from sys import stdin, stdout N = int(stdin.readline()) D = {} for i in range(N): inp = stdin.readline().split(' ') D[inp[0]]=int(inp[1])
for tup in sorted(D.items(), key=lambda x: x[1], reverse=True): print(tup[0], tup[1]) In that problem the solution is a STABLE sort. В этой задаче решением является УСТОЙЧИВАЯ сортировка. Спасибо за ответ! Не понял этого из описания задачи Is this a problem for counting the number of shortest common superstrings ??? Python3: TLE #8 Python2: AC 0.8 sec Code is the same. (Pseudo-vector product) Edited by author 28.04.2017 17:08 Posting code is not a nice idea. Moreover it is not ideal. Could anyone help me? In general this task is quite hard to make bugs if you know what to do... What is your approach? Написал лобовой вариант и всё равно WA10! Значит, вывод не верен. Кто может подсказать, как выводить ответ?(Форум не помог) #define _CRT_SECURE_NO_WARNINGS #define mk make_pair #include <string> #include <map> #include <iostream> using namespace std; typedef map <string, int> mymap; const int nmax = 100005; mymap t[4 * nmax]; mymap answer[nmax]; string word[nmax]; int cnt[nmax]; int n, m; string w_print[11]; int c_print[11]; mymap Search(int L, int R); int BinaryDown(int L, int R, string s); int BinaryUp(int L, int R, string s); mymap Optimal(mymap map1, mymap map2); void Print(mymap M); void QSort_W(int L, int R); void QSort2(int L, int R); void QSort3(int L, int R); int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> word[i] >> cnt[i]; QSort_W(1, n); cin >> m; for (int i = 1; i <= m; i++) { string s; cin >> s; int L, R; L = BinaryDown(1, n, s); R = BinaryUp(1, n, s); answer[i].clear(); if (L != -1 && R != -1) answer[i] = Search(L, R); } for (int i = 1; i <= m; i++) { Print(answer[i]); if(i!=m) cout<<endl; if(!(answer[i].empty()) && i!=m) cout<<endl; } return 0; } mymap Search(int L, int R) { mymap res; res.clear(); for(int i=L;i<=R;i++) { mymap x; x.insert(mk(word[i],cnt[i])); res=Optimal(res,x); } return res; } void Print(mymap M) { int n = 0; for (mymap::iterator it = M.begin(); it != M.end(); it++) { w_print[++n] = it->first; c_print[n] = it->second; } if (n == 0) return; QSort2(1, n); for (int i = 1; i <= n;) { int j = i + 1; while (j <= n && c_print[j] == c_print[i]) j++; QSort3(i, j - 1); i = j; } for (int i = 1; i<n; i++) cout << w_print[i] << endl; cout << w_print[n]; } void QSort2(int L, int R) { int i, j; int X = c_print[(L + R) / 2]; i = L, j = R; while (i <= j) { while (c_print[i] > X) i++; while (c_print[j] < X) j--; if (i <= j) { string Y = w_print[i]; w_print[i] = w_print[j]; w_print[j] = Y; int k = c_print[i]; c_print[i] = c_print[j]; c_print[j] = k; i++; j--; } } if (L < j) QSort2(L, j); if (i < R) QSort2(i, R); } void QSort3(int L, int R) { int i, j; string X = w_print[(L + R) / 2]; i = L, j = R; while (i <= j) { while (w_print[i] < X) i++; while (w_print[j] > X) j--; if (i <= j) { string Y = w_print[i]; w_print[i] = w_print[j]; w_print[j] = Y; int k = c_print[i]; c_print[i] = c_print[j]; c_print[j] = k; i++; j--; } } if (L < j) QSort3(L, j); if (i < R) QSort3(i, R); } void QSort_W(int L, int R) { int i, j; string X = word[(L + R) / 2]; i = L, j = R; while (i <= j) { while (word[i] < X) i++; while (word[j] > X) j--; if (i <= j) { string Y = word[i]; word[i] = word[j]; word[j] = Y; int k = cnt[i]; cnt[i] = cnt[j]; cnt[j] = k; i++; j--; } } if (L < j) QSort_W(L, j); if (i < R) QSort_W(i, R); } int BinaryDown(int L, int R, string s) { for(int i=L;i<=R;i++) if(s==word[i].substr(0, s.length())) return i; return -1; } int BinaryUp(int L, int R, string s) { for(int i=R;i>=L;i--) if(s==word[i].substr(0, s.length())) return i; return -1; } mymap Optimal(mymap map1, mymap map2) { mymap res; res.clear(); if (map1.size() + map2.size() <= 10) { res = map1; for (mymap::iterator it = map2.begin(); it != map2.end(); it++) res.insert(mk(it->first,it->second)); return res; } else { res = map1; for (mymap::iterator it = map2.begin(); it != map2.end(); it++) { if (res.size() < 10) res.insert(mk(it->first, it->second)); else { if (res.begin()->second < it->second) { res.erase(res.begin()); res.insert(mk(it->first, it->second)); } } } return res; } } void Print(mymap M) { ... for (int i = 1; i<=n; i++) cout << w_print[i] << endl; } for (int i = 1; i <= m; i++) { Print(answer[i]); if(i!=m) cout<<endl; } My AC code: input: > 3 3 > 1 2 1 > 1 2 1 > 1 3 1 > -1 output: > No solution. Why not > 1 2 There are two roads connecting "1" and "2", so the route could be 1 - 2 - 1, with different road 1 - 2 and 2 -1 "Each sightseeing route is a sequence of road numbers y1, …, yk, k > 2." Oops. Sorry for bothering! "Each sightseeing route is a sequence of road numbers y1, …, yk, k > 2." Have you guys thought about exact, long arithmetic check? if you get it, try to change g. i misread the statement and my g was equal to 9.81, not 9.8, then i fixed it and got AC Maybe correct name for that problem is "SINE dance"? "Sinus" is something about anathomy. |
|