| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| This is my solution, and it be Accepted, C++ | Manh Le Van | 2023. Дональд-почтальон | 23 апр 2016 15:55 | 3 |
/* Le Van Manh Hanoi University Of Science And Technology Viet Nam */ #include <iostream> #include <stdio.h> #include <string> using namespace std; int readAddressToValue(){ int v = 0; string a; cin>>a; if( a=="Alice"||a=="Ariel"||a=="Aurora"|| a=="Phil"||a=="Peter"||a=="Olaf"|| a=="Phoebus"||a=="Ralph"||a=="Robin"){ v = 0; }else if( a=="Bambi"||a=="Belle"||a=="Bolt"|| a=="Mulan"||a=="Mowgli"||a=="Mickey"|| a=="Silver"||a=="Simba"||a=="Stitch"){ v = 1; }else{ v = 2; } return v; } int main(){ int address0; int address1; int steps = 0; int n; cin>>n;
address0 = readAddressToValue(); steps+= address0 - 0; for(int i=1;i<n;i++){ address1 = readAddressToValue(); steps += abs(address1 - address0); address0 = address1; } cout<<steps; return 0; } Edited by author 20.02.2016 13:17 потому что не подключил <cmath> |
| This problem don't need any complicated sortings | Grandmaster | 1100. Таблица результатов | 23 апр 2016 15:05 | 1 |
You just need an array with 100 elements so in every position M, you add the ID using a dynamic structure such as "vector" in C++. (Theoretical complexity O(n)) Now you go from 100 to 0 and then print every element from each position M. Edited by author 23.04.2016 15:06 |
| I use O(N^3) and got AC in 0.156, why??? | hoan | 1167. Bicolored Horses | 23 апр 2016 00:56 | 4 |
if you have a better algo please tell to me. plz help!!!!!!!!!!!!!!! The data is too weak, I use O(n^3) got an AC in 0.097ms~~ I use O(N^3) and got AC in 0.156 too It's not the problem of tests program which does exacltly n^3 operations work for 0.28, so why you hink tests are weak? |
| Easy 5 second AC | IlushaMax | 1935. Слёзы утопленников | 23 апр 2016 00:39 | 1 |
|
| what is my problen on wa2?? on c++ | nick nikuradze | 1196. Экзамен по истории | 22 апр 2016 13:23 | 6 |
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int N,M,a,b; vector <int> t; vector <int> s; vector <int> st; cin>>N; for(int i=0; i<N; i++) { cin>>a; t.push_back(a); } cin>>M; for(int i=0; i<M; i++) { cin>>b; s.push_back(b); } for(int i=0; i<M; i++) { for(int j=0; j<N; j++) { if(s[i]==t[j]) st.push_back(s[i]); } } sort(st.begin(),st.end()); cout<<st.size(); return 0; } "Professor's list is sorted in non-descending order", so duplicates allowed. You are pushing s[i] into out not once but as many times as equal numbers found in t. Break internal cycle when first equality found. But. After I fixed your code I received TLE 8 because of "N*M" complexity. You must optimize perfomance (and should - memory usage). Edited by author 20.04.2016 13:21 Edited by author 20.04.2016 13:21 but what can i do to solve TLE8 C.O. thinks you should optimize your program. 1) Remove s and st arrays. You can - read students value, check it, increase counter if necessary. 2) Speed up checking if date is in professor dates. You can use binary search over sorted array, std::set, std::unordered_set for example. Now I have this code but I have compilation eror why? #include <iostream> #include <vector> #include <set> using namespace std; int main() { int N,M,a,b,counter=0; vector <int> t; set <int> s; cin>>N; for(int i=0; i<N; i++) { cin>>a; t.push_back(a); } cin>>M; for(int i=0; i<M; i++) { cin>>b; s.insert(b); } for(int i=0; i<s.size(); i++) { for(int j=0; j<t.size(); j++) { if(s[i])==t[j]) {counter++; break;} } }
cout<<counter; return 0; } |
| This is AC one. | Hunter | 1567. SMS-спам | 22 апр 2016 11:51 | 1 |
import java.util.Scanner; public class SMSspam2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s =in.nextLine(); char a[] = s.toCharArray();
int count = 0; for(int i=0;i<s.length();i++){ count = count+getCount(a[i]); } System.out.println(count); in.close(); } private static int getCount(char a) { int count =0; if (a == 'a' || a == 'd' || a == 'g' || a== 'j' || a== 'm' || a == 'p' || a == 's' || a== 'v' || a == 'y' || a== '.' || a== ' ') { count++; } if (a== 'b' || a == 'e' || a== 'h' || a == 'k' || a == 'n' || a == 'q' || a== 't' || a== 'w' || a== 'z' || a == ',') { count = count + 2; } if (a== 'c' || a== 'f' || a == 'i' || a == 'l' || a== 'o' || a== 'r' || a == 'u' || a== 'x' || a == '!') { count = count+ 3; } return count; } } |
| WA# 6 What is wrong? | Joe | 1910. Руины титанов: сокрытый вход | 21 апр 2016 18:50 | 3 |
#include <stdio.h> int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int n; scanf("%d", &n); long *sections = new long[n]; for (int i = 0; i < n; i++){ scanf("%ld", §ions[i]); } if (n==3){ printf("%ld %d", sections[0] + sections[1] + sections[2], 2); } else{ int i = 0; int maxpoint = i; while (i + 3 < n){ int j = i + 1; if (sections[i] + sections[i+1] + sections[i+2] < sections[j] + sections[j+1] + sections[j+2]){ maxpoint = j; } i++; } printf("%ld %d", sections[maxpoint] + sections[maxpoint+1] + sections[maxpoint+2], maxpoint+2); } return 0; } Input: 5 1 2 3 4 5 Output: 12 4 ENG: Read carefully the terms. Numbers do not necessarily have to be the same. (Google Translate) RUS: Внимательно читайте условие. Числа не обязательно должны быть одинаковыми. You should not compare sum with the previous sum, but the max sum. Considering sequence: 1 6 6 6 1 1 1 2 2 2 |
| Пожалуйста, объясните балбесу, как её решать. | Владислав | 1001. Обратный корень | 20 апр 2016 22:20 | 2 |
var a, x: extended; begin readln (a); x:= sqrt (a); writeln (x); end. Выдаёт неправильный ответ. Firstly you should read task carefully. How many numbers are in input? How many numbers your program process? |
| Help!I can not figure out about the limited time. | Hunter | 1209. 1, 10, 100, 1000... | 20 апр 2016 20:09 | 1 |
import java.util.Scanner; public class Digitals { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int a[] = new int[N]; int b[] = new int[N]; int sum = 0; for (int i = 0; i < N; i++) { a[i] = in.nextInt(); sum = 1; for (int j = 0;; j++) { sum = sum + j; if (sum == a[i]) { b[i] = 1; break; } if (sum > a[i]) { b[i] = 0; break; } } } for (int p = 0; p < N - 1; p++) System.out.print(b[p] + " "); System.out.println(b[N - 1]); in.close(); } } |
| Time error | Levan | 2035. Очередной пробный тур | 20 апр 2016 18:08 | 2 |
How do it more fast? #include <iostream> using namespace std; int main() { int x, y, c;
cin >> x >> y >> c;
if((x + y) < c) { cout << "Impossible" << endl; } else { for(int i = 0; i <= x; i++) { for(int j = 0; j <= y; j++) { if((i + j) == c) { cout << i << " " << j << endl; return 0; } } } } } Edited by author 13.10.2015 20:23 Edited by author 13.10.2015 20:23 Here is other way to solve If U have X u do not need finding Y Edited by author 20.04.2016 18:25 |
| wrong solution for example | Daniel Moldovan | 2043. Садовод Кирилл 2 | 20 апр 2016 01:11 | 1 |
There are 21 steps in this sequence: 1, 2, 3, 4, 5, 6, out, 6, 7, 8, 9, 10, 11, 12, out, 12, 11, 12, 13, 14, 15 |
| A+B Python | Sergey | 1000. A+B Problem | 19 апр 2016 19:21 | 4 |
a = int(input()) b = int(input()) print (a+b) _____________________ почему не правильно пишет? Execute example as is - use one line input - "1<space>5<eol>". You will see your solution doesn't work. Должно быть правильно... Я так же писала Не правильно потому, что ввод должен быть не: а - интер, b - интер, а: а - пробел b - интер.. |
| TLE on #46 | Talgat | 1379. Транспортировка кружек | 18 апр 2016 05:37 | 2 |
I'm using BS + Dijkstra but I'm getting TLE, why? I optimized solution by using edges that have capacity >= 3 * 10^6, implemented BS with iterations (without "while"), but keep getting TLE. I had TLE 46 when i was checking for time[N] <= 1440 only after my BFS was complete. But when i moved this condition inside my BFS, to check on it after getting every new wave of vertices, i got AC in 0.078! Truly surprising, wasn't expecting to make that much difference by moving a single line. My BFS shouldn't really be that bad either... |
| Test 5? | Ekaterina | 2035. Очередной пробный тур | 17 апр 2016 23:12 | 2 |
|
| k=7 | Temur | 1023. Пуговицы | 17 апр 2016 15:16 | 2 |
k=7 Temur 25 ноя 2015 16:33 Re: k=7 IlushaMax 17 апр 2016 15:16 No. Because we know that if k=3 then answer 2. So we can remove 3 buttons from bunch. And find answer for k=4, but answer for this input will be 3. So 2!=3 and such answer is wrong. So answer will be 6 (cause we can't divide it on groups answer for those we know). |
| WA #2 runtime error (access violation)who can tell me why? | gingogo | 1136. Парламент | 16 апр 2016 23:25 | 1 |
|
| Hint : How to find out reason of WA | IlushaMax | 2035. Очередной пробный тур | 16 апр 2016 15:32 | 1 |
Just list all of cases like x>=y>=c or y>=x>=c and you'll understand |
| Whats wrong in this solution. (C++) | Tapish | 1001. Обратный корень | 16 апр 2016 02:36 | 1 |
|
| Please help, why WA on test #6? | Natasha | 1207. Медиана на плоскости | 15 апр 2016 16:12 | 1 |
//1152 #include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int n, x0, y0, index0; cin >> n; if (n == 2){ cout << 1 + ' ' + 2; } else { vector<vector<int>> p(n, vector<int>(2)); // [x, y] vector<double> k(n); for (int i = 0; i < n; i++) { cin >> p[i][0] >> p[i][1]; } x0 = y0 = 2147483647; for (int i = 0; i < n; i++) { if (p[i][0] < x0 ||p[i][0] == x0 && p[i][1] < y0){ x0 = p[i][0]; y0 = p[i][1]; index0 = i; } } for (int i = 0; i < n; i++) { //y = kx + m if (i == index0) { k[i] = 9223372036854775807; } else { if (x0 == p[i][0]) { k[i] = 9223372036854775807; } else { k[i] = (p[i][1] - y0) / (p[i][0] - x0); } } }
vector<int> d(n); for (int i = 0; i < n; i++) { d[i] = i; } double tempD; int tempI; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < i; j++) { if (k[j + 1] < k[j]) { tempD = k[j + 1]; k[j + 1] = k[j]; k[j] = tempD; tempI = d[j + 1]; d[j + 1] = d[j]; d[j] = tempI; } } } cout << index0 + 1 << ' ' << d[n / 2 -1] + 1; } return 0; } |
| Please help with solution | g00d | 1115. Корабли | 15 апр 2016 03:30 | 2 |
I wrote program on Python 3, but second test is wrong for me. Why? I need a hint. Maybe, you can wrote test for my program? Idea: 1. sort length descending 2. take first that smaller SUM in row 3. reduce SUM and colored ship 4. take next 5. finally for SUM if they == 0 -> go to next row My solution: [n, m] = [ int(x) for x in input().split() ] a = [] for i in range(n): a.append(int(input())) b = [] for i in range(m): b.append(int(input())) a.sort(reverse=True) color = [-1 for x in range(n)] i = 0 while i < m: s = b[i] z = 0 while z < n: aa = [] j = z while s > 0: while j < n and a[j] > s : j += 1 if j >= n: for ee in aa: s += a[ee] color[ee] = -1 aa = [] break elif color[j] != -1: j += 1 else: s = s - a[j] aa.append(j) color[j] = i z += 1 if s == 0: break i += 1 for i in range(m): aa = [] cnt = 0 for j in range(n): if color[j] == i: aa.append(a[j]) cnt += 1 print(cnt) aa.sort(reverse=True) ab = [str(x) for x in aa] ss = " ".join(ab) print(ss) please, never post your code here! use pastebin or ideone! |