Skip to content

Instantly share code, notes, and snippets.

@IvanIsCoding
IvanIsCoding / arvore.cpp
Last active December 9, 2017 13:00
Seletiva IOI 2017
// Ivan Carvalho
// Árvore- Seletiva IOI - OBI 2017
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5*1e5 + 10;
const int MAXL = 20;
vector<int> grafo[MAXN],esq,dir,val;
int ancestral[MAXN][MAXL],raiz[MAXN],n,q,segPtr,valor[MAXN],nivel[MAXN];
void utilidade(){
esq.push_back(0);
@IvanIsCoding
IvanIsCoding / caminhos.cpp
Created December 5, 2017 18:59
Seletiva IOI 2017
// Ivan Carvalho
// Caminhos- Seletiva IOI - OBI 2017
#include <bits/stdc++.h>
#define MT make_tuple
using namespace std;
typedef long long ll;
typedef tuple<ll,ll,ll> trinca;
typedef pair<ll,ll> ii;
const int MAXN = 2*1e4;
vector<ii> grafo[MAXN];
@IvanIsCoding
IvanIsCoding / selecao.cpp
Created December 5, 2017 18:58
Seletiva IOI 2017
// Ivan Carvalho
// Seleção - Seletiva IOI - OBI 2017
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2*1e6 + 10;
int A[MAXN],B[MAXN],soma[MAXN],N;
ll K;
int ax,bx,cx,mx,ay,by,cy,my;
int func(int val){
@IvanIsCoding
IvanIsCoding / domino.cpp
Created November 9, 2017 09:57
Seletiva IOI 2013
// Ivan Carvalho
// Dominó - Seletiva IOI - OBI 2013
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 10;
int m[MAXN][3];
int dp[MAXN][2][2][2];
int N;
int solve(int pos,int a1,int a2,int a3){
if(pos > N + 1) return 0;
@IvanIsCoding
IvanIsCoding / serrote.cpp
Created November 8, 2017 15:26
Seletiva IOI 2015
// Ivan Carvalho
// Serrote - Seletiva IOI - OBI 2015
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 10;
const ll MOD = 1e9 + 7;
ll dp[MAXN][MAXN],n,k;
ll solve(ll tam,ll dentes){
if(tam == 3){
@IvanIsCoding
IvanIsCoding / robo.cpp
Created October 29, 2017 14:14
Seletiva IOI 2014
// Ivan Carvalho
// Robô - Seletiva IOI - OBI 2014
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 1e9;
int X,Y,seg[4*MAXN],lazy[4*MAXN],L[MAXN],R[MAXN];
void propagate(int pos,int left,int right){
if(lazy[pos] == 0) return;
seg[pos] = lazy[pos];
@IvanIsCoding
IvanIsCoding / binaria.cpp
Created October 29, 2017 13:30
Seletiva IOI 2015
// Ivan Carvalho
// Binária - Seletiva IOI - OBI 2015
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 101;
const ll MOD = 1e9 + 7;
ll dp[MAXN][MAXN];
ll binomial[MAXN][MAXN];
ll N,K,H,entrada[MAXN];
@IvanIsCoding
IvanIsCoding / permutacao.cpp
Created October 28, 2017 22:40
Seletiva IOI 2014
// Ivan Carvalho
// Permutação - Seletiva IOI - OBI 2014
#include <bits/stdc++.h>
#define gc getchar_unlocked
inline void print(int n){
char buf[11];
buf[10] = ' ';
int i = 9;
while (n){
buf[i--] = n % 10 + '0';
@IvanIsCoding
IvanIsCoding / risco.cpp
Created October 27, 2017 22:11
Seletiva IOI 2014
// Ivan Carvalho
// Risco - Seletiva IOI - OBI 2014
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
if(a < b) swap(a,b);
if(b == 0) return a;
return gcd(b,a%b);
}
int main(){
@IvanIsCoding
IvanIsCoding / taxa.cpp
Created September 7, 2017 12:01
Solução OBI 2017
// Ivan Carvalho
// Taxa - Fase 3 Programação Nível 2 - OBI 2017
// O(N^3)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 401;
const int INF = 1e9;
double fator;
int dp[MAXN][MAXN],acumulada[MAXN],vetor[MAXN],total,resp,n;
int calcula(int i,int j){