Posts

Showing posts from January, 2017

Codeforces Blown Garland

/* Lionel Messi is such a player that you may catch him, you may touch him, you may feel him and definitely you may Love him. Lionel Messi is Messi. A little Magician in this World. */ // Accepted #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<char, int>mpci; typedef unsigned long long ull; const int mod = 1000007; const int high = 6; int ar[high]; int main() {     fast;     string in;     int i , len=0 , j;     char ch[] = {'R' , 'B' , 'Y' , 'G'};     mpci mp;     while(cin >> in)     {         len = in.length();         mp.clear();         for(i=0; i<len; i++)         {            

Hacker Rank Minimum Edges in a Layered Graph

/* Lionel Messi is such a player that you may catch him, you may touch him, you may feel him and definitely you may Love him. Lionel Messi is Messi. A little Magician in this World. */ #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef unsigned long long ull; const int mod = 1000007; const int high = 100; int main() {     fast;     int n , k;     while(cin >> n >> k)     {         if(n < k) outn(-1);         else if(n == k) outn(n-1);         else if(n > k)         {             if(k == 2) outn(-1);             else             {                 outn((k - 1) + (2 * (n - k))); // every vertex is connected to another for

UVa 11503 - Virtual Friends

// Accepted #include<cstdio> #include<algorithm> #include<cstring> #include<map> #include<vector> #include<cmath> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef unsigned long long ull; typedef map<string, int>mpsi; const int mod = 1000007; const int high = 100003; int par[high] , num[high]; int findd(int n) {     return par[n] == n ? n : (par[n] = findd(par[n])); } int unionn(int a , int b) {     int u = findd(a);     int v = findd(b);     if(u == v) return num[u];     else     {         if(num[u] > num[v])         {             num[u] += num[v];             par[v] = u;             return num[u];         }         num[

Codeforces Ilya and tic-tac-toe game

/* Lionel Messi is such a player that you may catch him, you may touch him, you may feel him and definitely you may Love him. Lionel Messi is Messi. A little Magician in this World. */ #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef unsigned long long ull; const int mod = 1000007; const int high = 4; char ch[5][5]; bool horizontal() {     int i , j;     bool decision=false;     for(i=0; i<high; i++)     {         for(j=0; j<high; j++)         {             if(ch[i][j] == 'x')             {                 if(ch[i][j+1]=='x' and ch[i][j+2]=='.')                 {                     decision = true;       

UVa 10685 - Nature

/* Lionel Messi is such a player that you may catch him, you may touch him, you may feel him and definitely you may Love him. Lionel Messi is Messi. A little Magician in this World. */ #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef unsigned long long ull; typedef map<string, int>mpsi; const int mod = 1000007; const int high = 5003; int par[high] , num[high]; void set_initial(int n) {     int i=0;     for(i=1; i<=n; i++)     {         par[i] = i;         num[i] = 1;     } } int findd(int n) {     if(par[n] == n) return n;     else return par[n] = findd(par[n]); } void unionn(int a , int b) {     int u = findd(a);     int v =

UVa 459 - Graph Connectivity

// Solution Type: Disjoint Set /* Lionel Messi is such a player that you may catch him, you may touch him, you may feel him and definitely you may Love him. Lionel Messi is Messi. A little Magician in this World. */ #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<char, int>mpci; const int mod = 1000007; const int high = 100; mpci mp; int par[30]; void init() {     int  i=1;     for(char c='A' ; c<='Z'; c++ , i++)     {         mp[c] = i;     } } void makke_sett(int n) {     for(int i=1; i<=n; i++)     {         par[i] = i;     } } int findd(int n) {     if(par[n] == n) return n;     else     {        

Hacker Rank Lucky Numbers

/* Lionel Messi is such a player that you may catch him, you may touch him, you may feel him and definitely you may Love him. Lionel Messi is Messi. A little Magician in this World. */ #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int mod = 1000007; const int high = 100; // modified needed................................. LL bigmod(LL a , LL b , LL c) {     if(!b) return 1;     if(!(b & 1))     {         LL x = bigmod(a , b / 2 , c)%c;         return ((x % c) * (x % c ))%c;     }     else         return ((a%c) * (bigmod(a , b-1, c) %c ))%c; } //...................................................... LL modInverse(LL a, LL mod){retu

Hacker Rank Candy Piles

/* Lionel Messi is such a player that you may catch him, you may touch him, you may feel him and definitely you may Love him. Lionel Messi is Messi. A little Magician in this World. */ #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int mod = 1000007; const int high = 100003; // modified needed................................. LL bigmod(LL a , LL b , LL c) {     if(!b) return 1;     if(!(b & 1))     {         LL x = bigmod(a , b / 2 , c)%c;         return ((x % c) * (x % c ))%c;     }     else         return ((a%c) * (bigmod(a , b-1, c) %c ))%c; } //...................................................... LL modInverse(LL a, LL mod){r

Codeforces Magic Numbers

/* Lionel Messi is such a player that you may catch him, you may touch him, you may feel him and definitely you may Love him. Lionel Messi is Messi. A little Magician in this World. */ #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define nl puts("") #define psb push_back typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; const int mod = 1000007; const int high = 100; int main() {     fast;     string s;     int len , i , one , four;     while(cin >> s)     {         len = s.length();         one = four  = 0;         if(s[0] != '1')         {             outn("NO");             continue;         }         bool magic=false , other=false;         for(i=0; i<len; i++)         {             four = 0;