Posts

FIXING TYPOS CODEFORCES STRINGS

  #include <bits/stdc++.h> using   namespace   std ; int   main () {   char   a ,  b = 0 ,  c = 1 ,  d = 2 ;    while ( cin >> a ){     if ( ! ( a == b   &&   b == c )  &&   ! ( a == b   &&   c == d )){       cout << a ;       d = c ;       c = b ;       b = a ;    }  } }  

B. FLAG DAY codeforces

#include < bits / stdc ++. h > using namespace std ;   int main () { ios_base :: sync_with_stdio ( 0 ); cin . tie ( 0 ); int i , n , m , a [ 100005 ]={ 0 }; cin >> n >> m ; for ( i = 0 ; i < m ; i ++) { int v [ 3 ], q = 0 ; for ( int j = 0 ; j < 3 ; j ++) { cin >> v [ j ]; q += a [ v [ j ]]; } for ( int j = 0 , c = 1 ; j < 3 ; j ++) { if ( c == q ) ++ c ; if (! a [ v [ j ]]) a [ v [ j ]]= c ++; } } for ( i = 1 ; i <= n ; i ++) { cout << a [ i ]<< ' ' ; } }

BIG SEGMENT CODEFORCES NICE IMPLEMENTATION

#include <iostream> using namespace std ; int main (){ int n , a , b , c , d , ans =- 1 ; cin >> n ; for ( int i = 0 ; i < n ; i ++){ cin >> a >> b ; if ( i == 0 ){ c = a ; d = b ;} if ( a < c ){ c = a ; ans =- 1 ;} if ( d < b ){ d = b ; ans =- 1 ;} if (( a == c )&&( b == d )) ans = i + 1 ;} cout << ans ;}

LITTLE GIRL AND GAME. My first FLUKE CODE that worked !

#include <bits/stdc++.h> using   namespace   std ; #define   iter ( a ,  b ,  c )  for ( auto (a)  =  (b); (a)  <  (c);  ++ (a)) #define   mod   1000000007 #define   pb  push_back #define   ff  first #define   ss  second #define   FIO   ios_base :: sync_with_stdio ( false );  cin . tie ( NULL ); #define   test ( w )  int  w; cin >> w; while (w -- ) int   main () {     string   s ;  cin >> s ;    map < char , int >   m ;    iter (i, 0 , s . length ())  m [ s [ i ] ] ++ ;    int   count = 0 ;    for ( auto   x : m )  if ( x . second % 2 == 1 )  count ++ ;    cout << ( count % 2 == 1   ||   count == 0   ? "First" : "Second" ) << endl ;    return   0 ; }  

AIRPORT SIMPLE IMPLEMENTATION CODEFORCES

#include < bits / stdc ++. h > using namespace std ; int n , m , a [ 500500 ], b [ 500500 ], ans , res ; int main (){ cin >> m >> n ; for ( int i = 1 ; i <= n ;++ i ){ cin >> a [ i ]; b [ i ]= a [ i ]; } for ( int i = 1 ; i <= m ;++ i ){ sort ( a + 1 , a + n + 1 ); sort ( b + 1 , b + n + 1 ); ans += a [ n ]; a [ n ]--; res += b [ 1 ]; b [ 1 ]--; if (! b [ 1 ]) b [ 1 ]= 12345679 ; } cout << ans << " " << res ; return 0 ; }

present from lina codeforces

#include <bits/stdc++.h> using   namespace   std ; #define   iter ( a ,  b ,  c )  for ( auto (a)  =  (b); (a)  <  (c);  ++ (a)) #define   mod   1000000007 #define   pb  push_back #define   ff  first #define   ss  second #define   FIO   ios_base :: sync_with_stdio ( false );  cin . tie ( NULL ); #define   test ( w )  int  w; cin >> w; while (w -- ) int   main () {     int   n ;  cin >> n ;    iter (i, 0 , 2 * n + 1 ){      iter (k, 0 , abs ( n - i ))  cout << "  " ;      int   j = 0 ;      for (; j < n - abs ( n - i ); j ++ )  cout << j << " " ;      while ( j > 0 )  cout << j -- << " " ;      cout << 0 << end...

k-String codeforces

#include < bits / stdc ++. h > using namespace std ;   int main () { string a , b , c ; int n ; cin >> n >> a ; sort ( a . begin (), a . end ()); for ( int i = 0 ; i < a . size (); i += n ) b += a [ i ]; for ( int i = 0 ; i < n ; i ++) c += b ; b = c ; sort ( b . begin (), b . end ()); if ( b != a ) cout <<- 1 ; else cout << c ; return 0 ; }

A. DUBSTEP REGEX

#include <bits/stdc++.h> using   namespace   std ; #define   iter ( a ,  b ,  c )  for ( auto (a)  =  (b); (a)  <  (c);  ++ (a)) #define   mod   1000000007 #define   pb  push_back #define   ff  first #define   ss  second #define   FIO   ios_base :: sync_with_stdio ( false );  cin . tie ( NULL ); #define   test ( w )  int  w; cin >> w; while (w -- ) int   main () {     string   s ;  cin >> s ;    regex   p ( "WUB" );    cout << regex_replace ( s , p , " " );      return   0 ; }

E. POLYGON CODEFORCES

#include <bits/stdc++.h> using   namespace   std ; int   main () {      ios_base :: sync_with_stdio ( false );      cin . tie ( NULL );  cout . tie ( NULL );      int   t ;  cin >> t ;      while ( t -- ){          int   n ;  cin >> n ;          vector < string >   a ( n );          for ( int   i = 0 ; i < n ; i ++ )                  cin >> a [ i ] ;          bool   flag = true ;          for ( int   i = 0 ; i < n - 1 ; i ++ ){              for ( int   j = 0 ; j < n -...

LEXICOGRAPHICALLY MINIMUM STRING SPACE OPTIMISATION HACKEREARTH

     #include <bits/stdc++.h>      using   namespace   std ;      int   parent [ 27 ];            int   find ( int   i ){         if ( i == parent [ i ])         return   i ;         parent [ i ] = find ( parent [ i ]);         return   parent [ i ];     }            void   union1 ( int   x , int   y ){         parent [ max ( x , y )] = min ( x , y );     }            string   Solution  ( string   A ,  string   C ,  string   B ) {        // Write...

LEXICOGRAPHICALLY MINIMAL STRING HACKEREARTH

#include <bits/stdc++.h> using   namespace   std ; int   const   N = 28 ; int   arr [ N ] = { 0 },  mn [ N ] = { 0 }; void   initialise (){      for ( int   i = 0 ; i <= 26 ; i ++ ){          arr [ i ] = i ;          mn [ i ] = i ;     }      return ; } int   root ( int   i ){      while ( i != arr [ i ]){          i = arr [ i ];     }      return   i ; } void   wunion ( int   a ,  int   b ){      int   root_a = root ( a );      int   root_b = root ( b );      if ( root_a == root_b )  return ;      arr [ root_b ] = root_a ;      mn [ root_a ] = min ( mn [ ...

STILL MAXIMUM HACKEREARTH

#include <bits/stdc++.h> using   namespace   std ; int   const   N = 1e5 + 3 ; long   long   int   arr [ N ] = { 0 }, size [ N ] = { 0 },  minarr [ N ] = { 0 }, maxarr [ N ] = { 0 },  localmax = 0 ; void   initialise ( int   nodes ){      for ( int   i = 0 ; i <= nodes ; i ++ ){          arr [ i ] = i ;          size [ i ] = 1 ;     } } int   root ( int   i ){      while ( i != arr [ i ]){          i = arr [ i ];     }      return   i ; } void   Union ( int   a , int    b ){      int   root_a = root ( a );      int   root_b = root ( b );      if ( root_a == root_b )  return ;    ...