Posts

Showing posts from March, 2021

ARC116 - A - Odd vs Even

 /*     There is a pattern to solve this problem:     1 -> odd     2 -> same     3 -> odd     4 -> even     5 -> odd     6 -> same     7 -> odd     8 -> even     9 -> odd     10 -> same     11 -> odd     12 -> even     13 -> odd     14 -> same     15 -> odd     16 -> even     17 -> odd     18 -> same     19 -> odd     20 -> even     Observation:     1. same number of even and odd divisors are repeating after 4 steps     2. we are getting more even number of divisors which is divided by 4     3. a typical odd number is generating much number of odd divisors     Now, let's implement those observations... */ #include <bits/stdc++.h> using namespace std; #define sf scanf #define pf printf typedef long long LL; int main() {     int test;     LL N;     sf("%d", &test);     while(test--)     {         sf("%lld", &N);         if(N%4==2) pf("Same\n");         else if(N%4==0) pf("Even

Atcode ABC - A - Rotate

 #include<bits/stdc++.h> using namespace std; #define sf scanf #define pf printf const int high=1e3+5; int main() {     string s, ans="";     while(cin >> s)     {         int len = s.length();         for(int i=1; i<len; i++)         {             ans += s[i];         }         ans+=s[0];         cout << ans << "\n";         ans.clear();     }     return 0; }

Atcoder ABC 197 - B - Visibility

/*     Count '.' - from the same row and column and count each     Finally, subtract 3, as (x, y) repeated like 3 times */ #include<bits/stdc++.h> using namespace std; #define sf scanf #define pf printf const int high=1000+5; char adj[high][high]; int main() {     int i, j, h, w, x, y;     cin >> h >> w >> x >> y;     for(i=0; i<h; i++)     {         for(j=0; j<w; j++)         {             cin >> adj[i][j];         }     }     int cnt=0;     x--; y--;     for(i=x; i<h; i++) //row - down     {         if(adj[i][y]=='#') break;         cnt+=1;     }     for(i=x; i>=0; i--) // row - up     {         if(adj[i][y]=='#') break;         cnt+=1;     }     for(j=y; j<w; j++) // column - right     {         if(adj[x][j]=='#') break;         cnt+=1;     }     for(j=y; j>=0; j--) // column - left     {         if(adj[x][j]=='#') break;         cnt+=1;     }     cnt -= 3;     cout << cnt << &q

Codeforces #710 - Strange Table

 /*     Solving concept:     I have first found the position of x in "by columns":         This is note that the position is started from 1. So,         if(x % n == 0) then, row = n, col = x / n;         else row = x % n, col = (x / n) + 1;         This is an easy technique.         Mind that: you can not run any loop to find the position because of the large number of input and test cases.     Now, find, what will be value for that position (row, col) in "by rows":         Look, in "by rows" method - a number will be increased sequentially in side of a row. For example:         consider 3x5 matrix -         1 2 3 4 5         6 7 8 9 10         11 12 13 14 15         there should have exact 15 numbers/values. So, what will be value of (row, col)?     In "by columns" method 11 (given sample - Case 1 - test 3) would be found at position     (row = 11 % 3 = 2, col = 11 / 3 = 3 + 1 = 4)     I have 3x5 matrix. So, we might get exact 10 from a 2x5 matr