2021-10-03 20:00 ATCoder周賽
2021-10-03 20:00 ATCoder周賽
A 略
B 略
C - Select Mul
Problem Statement
You are given an integer N. Consider permuting the digits in N and separate them into two positive integers.
For example, for the integer 123, there are six ways to separate it, as follows:
- 12 and 3,
- 21 and 3,
- 13 and 2,
- 31 and 2,
- 23 and 1,
- 32 and 1.
Here, the two integers after separation must not contain leading zeros. For example, it is not allowed to separate the integer 101 into 1 and 01. Additionally, since the resulting integers must be positive, it is not allowed to separate 101 into 11 and 0, either.
What is the maximum possible product of the two resulting integers, obtained by the optimal separation?
- N is an integer between 1 and 10^9(inclusive).
- N contains two or more digits that are not 0.
Constraints
- 1≤N≤105
- 1≤Ai≤109
- 1≤X≤1018
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the maximum possible product of the two integers after separation.
AC程式碼
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<(r);++i)
typedef long long ll;
int main(){
string s;
cin>>s;
sort(s.rbegin(),s.rend());
string a,b;
rep(i,0,(int)s.size()){
if(i%2==0) a+=s[i];
else b+=s[i];
}
rep(i,0,(int)min(a.size(),b.size())){
if(a[i]!=b[i]){swap(a[i],b[i]); break;}
}
cout<<stoi(a)*stoi(b)<<endl;
}
D - FG operation
Problem Statement
There is an online game with N registered players.
Today, which is the 10^100-th day since its launch, the developer Takahashi examined the users' login history. It turned out that the i-th player logged in for Bi consecutive days from Day Ai , where Day 1 is the launch day, and did not log in for the other days. In other words, the i-th player logged in on Day Ai, Ai+1, …, Ai +Bi−1, and only on those days.
For each integer k such that 1≤k≤N, find the number of days on which exactly k players logged in.
Constraints
- 1≤N≤2×10^5
- 1≤Ai≤10^9
- 1≤Bi≤10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A1 B1
...
AN BN
Output
D1
D2
⋯
Dn
Here, Di denotes the number of days on which exactly k players logged in.
AC程式碼
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 200010;
typedef pair<int,int> pii;
#define rep(i,n) for(int i = 1; i <= n; ++i)
int main()
{
int n, a, b;
cin >> n;
vector<pii>x;
int ans[N];
rep(i,N) ans[i] = 0;
ans[0] = 0;
rep(i,n)
{
cin >> a >> b;
x.push_back({a, 1});
x.push_back({a + b, -1});
}
sort(x.begin(), x.end());
int cnt = 0;
for(int i = 0; i < x.size() - 1; ++i)
{
cnt += x[i].second;
ans[cnt] += x[i+1].first - x[i].first;
}
rep(i, n-1) cout << ans[i] <<" ";
cout << ans[n] << endl;
return 0;
}