A. Reverse a Substring
Easy to see that they meet the increasing order to comply with \ (NO \) , otherwise you can find a group, each record compare to the maximum.
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 300010;
int n;
char s[N];
int main(){
scanf("%d%s", &n, s + 1);
int maxn = s[1], k = 1;
for(int i = 2; i <= n; i++){
if(s[i] < maxn){
printf("YES\n%d %d\n", k, i);
return 0;
}
if(s[i] > maxn){
maxn = s[i];
k = i;
}
}
printf("NO\n");
return 0;
}
B. Game with Telephone Numbers
\ (Vasya \) exhausted all rounds can put several \ (8 \) thrown into the front, as long as this is greater than the number of rounds, it shows \ (Petya \) can not change it Guards.
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int N = 100010;
int n;
char s[N];
int main(){
scanf("%d%s", &n, s + 1);
int round = (n - 11) >> 1;
int cnt = 0;
for(int i = 1; i <= round && round <= n; i++){
if(s[i] == '8')cnt++, round ++;
}
int i = round + 1;
while(s[i] == '8' && i <= n) i++, cnt++;
if(cnt > (n - 11) >> 1) puts("YES");
else puts("NO");
return 0;
}
C. Alarm Clocks Everywhere
Obviously, y is set to \ (x [1] \) can be, because even before the set, or to go through \ (x [1] \) , or in \ (p \) jump up, there is no difference.
As long as we find a \ (p_j \) , so as to satisfy \ (p_j | A [I +. 1] - A [I] (. 1 <= I <n-) \) . (Divisible meaning)
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 300010;
int n, m;
LL x[N], p[N];
LL gcd(LL a, LL b){
return b ? gcd(b, a % b) : a;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%lld", x + i);
for(int i = 1; i <= m; i++)
scanf("%lld", p + i);
LL ans = x[2] - x[1];
for(int i = 2; i < n; i++)
ans = gcd(ans, x[i + 1] - x[i]);
for(int i = 1; i <= m; i++){
if(ans % p[i] == 0){
printf("YES\n%lld %d\n", x[1], i);
return 0;
}
}
printf("NO");
return 0;
}
D. Beautiful Array
I think the greatest contribution to the sum of the number of columns, but in fact, the greatest contribution may not be able to maximize the answer, so brutally \ (WA10 \) .
\ (WA \) fried Code:
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 300010, INF = 2147483647;
typedef long long LL;
int n, x, L[N];
LL a[N], f[N];
int main(){
scanf("%d%d", &n, &x);
for(int i = 1; i <= n; i++)
scanf("%lld", a + i);
if(x < 0){
f[1] = a[1];
L[1] = 1;
LL minn = f[1];
int k = 1;
for(int i = 2; i <= n; i++) {
if(f[i - 1] + a[i] < a[i]){
L[i] = L[i - 1];
f[i] = f[i - 1] + a[i];
}else{
L[i] = i;
f[i] = a[i];
}
if(f[i] < minn){
minn = f[i], k = i;
}
}
if(minn < 0){
for(int i = L[k]; i <= k; i++)
a[i] *= x;
}
}else{
f[1] = a[1];
L[1] = 1;
LL maxn = f[1];
int k = 1;
for(int i = 2; i <= n; i++) {
if(f[i - 1] + a[i] > a[i]){
L[i] = L[i - 1];
f[i] = f[i - 1] + a[i];
}else{
L[i] = i;
f[i] = a[i];
}
if(f[i] > maxn){
maxn = f[i], k = i;
}
}
if(maxn > 0){
for(int i = L[k]; i <= k; i++)
a[i] *= x;
}
}
f[1] = a[1];
LL maxn = f[1];
for(int i = 2; i <= n; i++){
f[i] = max(f[i - 1] + a[i], a[i]);
maxn = max(maxn, f[i]);
}
printf("%lld\n", max(maxn, 0ll));
return 0;
}
I looked out the solution to a problem directly autistic, in fact, can be set up
\ (F [0] \) for the current to \ (I \) is the right end, not added (X \) \ maximum value, it must be greater than \ (0 \)
\ (f [1] \) represents the start of a continuous calculation \ (* x \) , and if this time is not yet \ (f [0] \) large, then it is useless
\ (f [2] \) representative of the multiplication over, but also explore whether added \ (a [i] \)
If \ (X> 0 \) , then the \ (f [2] + a [i] \) will not be optimal
If \ (X <0 \) , there may be such a situation, the back of the front positive negative
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 300010, INF = 2147483647;
typedef long long LL;
int n, x, L[N];
LL a[N], f[3], ans = 0;
int main(){
scanf("%d%d", &n, &x);
for(int i = 1; i <= n; i++)
scanf("%lld", a + i);
for(int i = 1; i <= n; i++){
f[0] = max(f[0] + a[i], 0ll);
f[1] = max(f[0], f[1] + a[i] * x);
f[2] = max(f[1], f[2] + a[i]);
ans = max(ans, f[2]);
}
printf("%lld\n", ans);
return 0;
}
E. Guess the Root
Gaussian elimination \ (/ \) Lagrange polynomial will not, Gugu Gu.