Created
February 21, 2018 18:50
-
-
Save HarveyBrezinaConniffe/de6a89713313d52bd000e2c96621e488 to your computer and use it in GitHub Desktop.
AIPO 2018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import array | |
inp0 = input() | |
inp1 = input() | |
a = reversed(inp1) | |
st = '' | |
for b in a: | |
st += b | |
if(inp0 == st): | |
print('YES') | |
else: | |
print('NO') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <map> | |
using namespace std; | |
int main() { | |
int numcards; | |
cin >> numcards; | |
map<int, int> cards; | |
for(int i = 0;i < numcards;i++) { | |
int ccard; | |
cin >> ccard; | |
cards[ccard] = 1; | |
} | |
for(int i = 0;i <= 99;i++) { | |
if(cards[i] != 1) { | |
cout << i << ' '; | |
} | |
} | |
cout << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 | |
0 1 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
string in; | |
cin >> in; | |
char lnum = 0; | |
int length = 0; | |
int longest = 0; | |
for(int i = 0;i < in.length();i++) { | |
char num = in[i]; | |
if(num > lnum) { | |
length++; | |
lnum = num; | |
} | |
else { | |
if(length > longest) { | |
longest = length; | |
} | |
length = 1; | |
lnum = num; | |
} | |
} | |
cout << longest << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inp = input() | |
last = '' | |
clength = 0 | |
longest = 0 | |
for i in inp: | |
if i >= last: | |
clength += 1 | |
elif(clength > longest): | |
longest = clength | |
clength = 1 | |
else: | |
clength = 1 | |
last = i | |
if(clength > longest): | |
longest = clength | |
clength = 1 | |
print(longest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <bitset> | |
#include <vector> | |
using namespace std; | |
long long _sieve_size; | |
bitset<10000010> bs; | |
vector<int> primes; | |
void sieve(long long upperbound) { | |
_sieve_size = upperbound + 1; | |
bs.set(); | |
bs[0] = bs[1] = 0; | |
for(long long i = 2; i <= _sieve_size; i++) if (bs[i]) { | |
for(long long j = i*i; j <= _sieve_size; j += i) bs[j] = 0; | |
primes.push_back((int)i); | |
} | |
} | |
bool isPrime(long long N) { | |
if(N <= _sieve_size) return bs[N]; | |
for(int i = 0; i < (int)primes.size(); i++) | |
if(N%primes[i] == 0) return false; | |
return true; | |
} | |
int main() { | |
sieve(2000000); | |
int n, nums = 0; | |
cin >> n; | |
for(int i = 0;i <= n;i++) { | |
if((i >= 10 && i < 20) || (i >= 100 && i < 200) || (i >= 1000 && i < 2000) || (i >= 10000 && i < 20000) || (i >= 100000 && i < 200000) || (i >= 1000000 && i < 2000000) || (i >= 10000000 && i < 20000000)) { | |
//bool good = true; | |
//for(int j = 2;j < i;j++) { | |
// if(i%j == 0 && j != i) { | |
// good = false; | |
// break; | |
// } | |
//} | |
if(isPrime(i)) nums++; | |
} | |
} | |
cout << nums << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 0 | |
nums = 0 | |
n = int(input()) | |
for i in range(0, n): | |
if( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int main() { | |
string road; | |
int money; | |
cin >> road >> money; | |
vector<int> sections; | |
int numsec = 0; | |
int csec = 0; | |
char last; | |
for(int i = 0;i < road.length();i++) { | |
if(road[i] == '.' && last == 'X') { | |
sections.push_back(csec); | |
csec = 0; | |
numsec += 1; | |
} | |
else if(road[i] == 'X') { | |
csec += 1; | |
} | |
last = road[i]; | |
} | |
sections.push_back(csec); | |
csec = 0; | |
numsec += 1; | |
sort(sections.begin(), sections.end()); | |
int out = 0; | |
for(int i = 0;i < numsec-money;i++) { | |
out += sections[i]; | |
} | |
cout << out << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inp = input() | |
cols = inp.split(); | |
green = int(cols[1]) | |
red = int(cols[0]) | |
GREEN = 0 | |
RED = 1 | |
colors = {GREEN: green, RED: red} | |
maxlevel = 0; | |
def work(level, color, icolornums): | |
colornums = icolornums.copy() | |
colornums[color] -= level; | |
if(colornums[color] < 0): | |
return [-1, -1]; | |
else: | |
n1 = work((level+1), GREEN, colornums) | |
n2 = work((level+1), RED, colornums) | |
if not n1[0] == n2[0]: | |
m = max(n1[0], n2[0]) | |
if(m == n1[0]): | |
return [n1[0], n1[1]] | |
else: | |
return [n2[0], n2[1]] | |
else: | |
if(n1[0] == -1 and n2[0] == -1): | |
return [level, 1] | |
return [n1[0], n1[1]+n2[1]]; | |
w1 = work(1, GREEN, colors) | |
w2 = work(1, RED, colors) | |
if(w1[0] == w2[0]): | |
print((w1[1]+w2[1])%((10^9)+7)) | |
else: | |
m = max(w1[0], w2[0]); | |
if(w1[0] == m): | |
print(w1[1]%((10^9)+7)) | |
else: | |
print(w2[1]%((10^9)+7)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
green = input() | |
red = input() | |
level = 1 | |
GREEN = 0 | |
RED = 1 | |
ccolor = GREEN | |
colors = {GREEN: green, RED: red} | |
maxlevel = 0; | |
while True: | |
if(colors[ccolor]-level < 0): | |
maxlevel = level-1; | |
break; | |
else: | |
colors[ccolor] -= level; | |
level += 1; | |
ccolor = RED | |
colors = {GREEN: green, RED: red} | |
while True: | |
if(colors[ccolor]-level < 0): | |
if(level-1 > maxlevel): | |
maxlevel = level-1; | |
break; | |
else: | |
colors[ccolor] -= level; | |
level += 1; | |
print(maxlevel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
green = input() | |
red = input() | |
GREEN = 0 | |
RED = 1 | |
colors = {GREEN: green, RED: red} | |
maxlevel = 0; | |
def work(level, color, colornums): | |
colornums[color] -= level; | |
if(colornums[color] < 0): | |
return level; | |
else: | |
return max(work((level+1), GREEN, colornums), work((level+1), RED, colornums)); | |
print(max(work(1, GREEN, colors), work(1, RED, colors))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These were my solutions to the All Ireland Programming Olympiad 2018.