B - Memory Management System
#include
using namespace std;
struct nomd
{
int x,y,c;
}a[100006],b[100006],c[100006];
int cmp(nomd a,nomd b)
{
return a.x>t;
while(t--)
{
int n,m,w;
scanf("%d %d %d",&n,&m,&w);
for(int i=0;
i=x+1)
{
b[++k].x=x+1;
b[k].y=a[i].x-1;
b[k].c=b[k].y-b[k].x+1;
}
x=max(x,a[i].y);
}
if(x!=m)
b[++k].x=x+1,b[k].y=m,b[k].c=b[k].y-b[k].x+1;
//for(int i=1;
i<=k;
i++)
//printf("----%d %d %d\n",b[i].x,b[i].y,b[i].c);
int e=0,q=0;
for(int i=k;
i>=1;
i--)
{
if(b[i].c>q)
{
q=b[i].c;
c[++e].x=b[i].x;
c[e].y=b[i].y;
c[e].c=b[i].c;
}
}
for(int i=0;
i=o)
printf("%d %d\n",m-o+1,m);
else
printf("-1 -1\n");
break;
}
for(int j=1;
j<=e;
j++)
{
if(c[j].c>=o)
{
ok=1;
printf("%d %d\n",c[j].y-o+1,c[j].y);
break;
}
}
if(ok==0)
printf("-1 -1\n");
}
}
return 0;
}
C - Large GCD
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<
D - XOR Permutations
E - Building Strings
#include
using namespace std;
char s[3000+10];
char c[3000+10];
int val[100];
char ss[100];
int main(){
int _;
scanf("%d",&_);
while(_--){
for(int i=0;
i<100;
i++)
val[i]=1000;
int a,b;
scanf("%d%d",&a,&b);
scanf("%s",s);
scanf("%s",c);
for(int i=0;
i=1000){
printf("-1\n");
}else
printf("%d\n",sum);
}
return 0;
}
F - camelCase;
#include
using namespace std;
chara[2000];
int main()
{
int t;
cin>>t;
while(t--)
{
scanf("%s",a);
int len=strlen(a);
int ans=0;
for(int i=0;
i='A'&&a[i]<='Z')
ans++;
}
if(a[0]>='a'&&a[0]<='z')
ans++;
if(ans<=7) printf("YES\n");
else printf("NO\n");
}
return 0;
}
【Gym - 102152】
G - The Special King
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<
H - The Universal String
#include
using namespace std;
const int maxn = 2e5 + 10;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1010;
int n;
char s[N];
int main(){
scanf("%d", &n);
getchar();
while(n--){
gets(s);
int len = strlen(s);
bool flag = true;
char pre = s[0];
for(int i = 1;
i < len;
i++){
if(pre == 'z'){
if(s[i] == 'a'){
pre = 'a';
continue;
}
else {
flag = false;
break;
}
}
else{
if(s[i]-'a'-1 == pre-'a'){
pre = s[i];
continue;
}
else {
flag = false;
break;
}
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}
I - Array Negations
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<> t;
while(t--){
int n, k, sum = 0;
;
int a[N];
scanf("%d%d", &n, &k);
int n0 = 0, nn = 0, n2 = 0;
for(int i = 0;
i < n;
i++) {
scanf("%d", &a[i]);
if(a[i] == 0) n0 ++;
else if(a[i] < 0) nn++;
else n2++;
}
sort(a, a+n);
int i = 0;
while(k && nn){
a[i] = -a[i];
i++;
k--;
nn--;
}
if(n0 > 0){
for(int i = 0;
i < n;
i++) sum += a[i];
}
else{
sort(a, a+n);
if(k & 1) {
a[0] = -a[0];
for(int i = 0;
i < n;
i++) sum += a[i];
}
else for(int i = 0;
i < n;
i++) sum += a[i];
}
printf("%d\n", sum);
}
return 0;
}
J - Grid Beauty
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<mp1;
unordered_mapmp2;
scanf("%d%d", &n, &m);
for(int i = 0;
i < n;
i++){
for(int j = 0;
j < m;
j++){
scanf("%d", &a[i][j]);
}
}
int ans = 0;
for(int i = 0;
i < n-1;
i++){
for(int j = 0;
j < m;
j++){
mp1[a[i][j]] ++;
mp2[a[i+1][j]]++;
}
for(int j = 0;
j < m;
j++){
if(mp1[a[i+1][j]] > 0){
ans += min(mp1[a[i+1][j]], mp2[a[i+1][j]]);
mp2[a[i+1][j]] = 0;
}
}
for(int j = 0;
j < m;
j++){
mp1[a[i][j]] = 0;
mp2[a[i+1][j]] = 0;
}
}
printf("%d\n", ans);
}
return 0;
}
K - Subarrays OR
#include
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define line cout<<"------------"<a, b, c;
for(int j = 0;
j < n;
j++){
a.clear();
a.insert(p[j]);
for(auto i : b){
a.insert(i | p[j]);
}
b = a;
for(auto i : a) c.insert(i);
}
printf("%d\n", c.size());
}
return 0;
}