Dashboard - Codeforces Round 866 (Div. 2) - Codeforces
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
int n , t;
string s;
signed main(){
IOS
cin >> t;
while(t --){
cin >> s;
n = s.size();
int res = 0;
if(s == "^") res += 1;
for(int i = 0 ; i < n ; i ++){
if(s[i] == '_'){
if(i == 0) res += 1;
else{
if(s[i - 1] == '_') res += 1;
}
}
}
if(s[n - 1] == '_') res += 1;
cout << res << "\n";
}
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
int t , n;
string s;
bool judge(string s){
for(int i = 0 ; i < n ; i ++) if(s[i] == '0') return 0;
return 1;
}
signed main(){
IOS
cin >> t;
while(t --){
cin >> s;
n = s.size();
int maxx = 0;
int res = 0;
if(judge(s)){
res = n * n;
}else{
s = s + s;
for(int i = 0 ; i < 2 * n ; i ++){
if(s[i] == '0') s[i] = ' ';
}
stringstream cin(s);
while(cin >> s){
int now = s.size();
maxx = max(maxx , now);
}
for(int i = 1 ; i <= maxx ; i ++){
res = max(res , i * (maxx - i + 1));
}
}
cout << res << "\n";
}
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
int t , n;
int a[N];
signed main(){
IOS
cin >> t;
while(t --){
cin >> n;
map<int , int>mp;
int res = 0;
for(int i = 1 ; i <= n ; i ++) cin >> a[i] , mp[a[i]] = 1;
for(int i = 0 ; ; i ++) if(mp[i] == 0){
res = i;break;
}
res += 1;
bool tag = 0;
if(mp[res]){
int l = 0 , r = 0;
for(int i = 1 ; i <= n ; i ++) if(a[i] == res){
l = i;break;
}
for(int i = n ; i >= 1 ; i --) if(a[i] == res){
r = i;break;
}
for(int i = l ; i <= r ; i ++) a[i] = res - 1;
mp.clear();
for(int i = 1 ; i <= n ; i ++) mp[a[i]] = 1;
int ans = 0;
for(int i = 0 ; ; i ++) if(mp[i] == 0){
ans = i;break;
}
if(res == ans) tag = 1;
}else{
int need = n - (res - 1);
if(need) tag = 1;
}
if(tag) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
int t , n ;
int area;
int a[N] , b[N];
bool vis[N];
int h , w;
set<PII>ans;
void solve(int x , int y){
int now_h = x , now_w = y;
if(x * y != area) return ;
for(int i = 1 ; i <= n ; i ++) vis[i] = 0;
priority_queue<PII , vector<PII> , less<PII>> hx , wx;
for(int i = 1 ; i <= n ; i ++){
hx.push({a[i] , i});
wx.push({b[i] , i});
}
for(int i = 1 ; i <= n ; i ++){
while(vis[hx.top().se]) hx.pop();
while(vis[wx.top().se]) wx.pop();
int pos = -1;
if(hx.top().fi == x) pos = hx.top().se;
if(wx.top().fi == y) pos = wx.top().se;
if(pos == -1) return ;
if(hx.top().fi == x){
y -= b[pos];
}else{
x -= a[pos];
}
vis[pos] = 1;
}
if(!(x * y)) ans.insert({now_h , now_w});
}
signed main(){
IOS
cin >> t;
while(t --){
cin >> n;
area = 0;
for(int i = 1 ; i <= n ; i ++){
cin >> a[i] >> b[i];
area += a[i] * b[i];
}
h = *max_element(a + 1 , a + 1 + n);
w = *max_element(b + 1 , b + 1 + n);
solve(h , area / h);
solve(area / w , w);
cout << ans.size() << "\n";
for(auto [x , y] : ans) cout << x << " " << y << "\n";
ans.clear();
}
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);