A - Rotation
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character Cij.
Write a program that prints YES
if this grid remains the same when rotated 180 degrees, and prints NO
otherwise.
Constraints
- Ci,j(1≤i≤2,1≤j≤3) is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
C11C12C13 C21C22C23
Output
Print YES
if this grid remains the same when rotated 180 degrees; print NO
otherwise.
Sample Input 1
pot top
Sample Output 1
YES
This grid remains the same when rotated 180 degrees.
Sample Input 2
tab bet
Sample Output 2
NO
This grid does not remain the same when rotated 180 degrees.
Sample Input 3
eye eel
Sample Output 3
NO
#include<bits/stdc++.h> #define _ cin.tie(0);ios::sync_with_stdio(false); using namespace std; int main(){ _ string str, tmp; while(cin >> str >> tmp){ reverse(str.begin(), str.end()); if(str == tmp) cout << "YES" << endl; else cout << "NO" << endl; } }
B - Around Square
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.
Constraints
- 1≤N≤109
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the largest square number not exceeding N.
Sample Input 1
10
Sample Output 1
9
10 is not square, but 9=3×3 is. Thus, we print 9.
Sample Input 2
81
Sample Output 2
81
Sample Input 3
271828182
Sample Output 3
271821169
#include<bits/stdc++.h> #define _ cin.tie(0);ios::sync_with_stdio(false); using namespace std; using LL = long long; int main(){ _ LL n, m; while(cin >> n){ for(LL i = 1; i*i <= n; i++) m = i * i; cout << m << endl; /* int i = sqrt(n); cout << i * i << endl; */ } }
C - Snuke Festival
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.
He has N parts for each of the three categories. The size of the i-th upper part is Ai, the size of the i-th middle part is Bi, and the size of the i-th lower part is Ci.
To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
Constraints
- 1≤N≤105
- 1≤Ai≤109(1≤i≤N)
- 1≤Bi≤109(1≤i≤N)
- 1≤Ci≤109(1≤i≤N)
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N A1 … AN B1 … BN C1 … CN
Output
Print the number of different altars that Ringo can build.
Sample Input 1
2 1 5 2 4 3 6
Sample Output 1
3
The following three altars can be built:
- Upper: 1-st part, Middle: 1-st part, Lower: 1-st part
- Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part
- Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part
Sample Input 2
3 1 1 1 2 2 2 3 3 3
Sample Output 2
27
Sample Input 3
6 3 14 159 2 6 53 58 9 79 323 84 6 2643 383 2 79 50 288
Sample Output 3
87
#include<bits/stdc++.h> #define _ cin.tie(0);ios::sync_with_stdio(false); using namespace std; #define rep(n) for(int i = 0; i < n; i++) #define Sort(a) sort(a.begin(), a.end()) using LL = long long; const int N = 100000 + 5; LL tree[N]; LL Query(int pos){ LL sum = 0; while(pos > 0){ sum += tree[pos]; pos -= (pos & -pos); } return sum; } void Add(int pos,LL num){ while(pos <= N){ tree[pos] += num; pos += (pos & -pos); } } vector<LL> a, b, c; int main(){ _ LL n, m; memset(tree, 0, sizeof(tree)); cin >> n; rep(n) { cin >> m; a.push_back(m); } rep(n) { cin >> m; b.push_back(m); } rep(n) { cin >> m; c.push_back(m); } Sort(a), Sort(b), Sort(c); for(int i = 0; i < n; i++){ auto tmp = lower_bound(a.begin(), a.end(), b[i]); int num = tmp - a.begin(); Add(i + 1, num); } LL sum = 0; for(auto &i : c){ auto tmp = lower_bound(b.begin(), b.end(), i); int cur = tmp - b.begin(); LL num = Query(cur); sum += num; } /** LL sum = 0; rep(n){ LL A = lower_bound(a.begin(), a.end(), b[i]) - a.begin(); LL B = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin()); sum += (A * B); }*/ cout << sum << endl; }