LeetCode Weekly Contest 146
問題文
省略
省略
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
return a>=b?a:b;
}
template<class S, class T> inline S chmax(S &a, T b){
if(a<b){
a=b;
}
return a;
}
int N;
int A[1000000];
class Solution{
public:
int maxAbsValExpr(vector<int>& arr1, vector<int>& arr2){
int i, mask, res=0;
N = arr1.size();
for(mask=0;mask<4;mask++){
for(i=0;i<N;i++){
if(mask&1){
if(mask&2){
A[i] = i +arr1[i]+arr2[i];
}
else{
A[i] = i +arr1[i]-arr2[i];
}
}
else{
if(mask&2){
A[i] = i -arr1[i]+arr2[i];
}
else{
A[i] = i -arr1[i]-arr2[i];
}
}
}
{
int KL2GvlyY, Lj4PdHRW;
if(N==0){
KL2GvlyY = 0;
}
else{
KL2GvlyY = A[0];
for(Lj4PdHRW=1;Lj4PdHRW<N;Lj4PdHRW++){
KL2GvlyY = min_L(KL2GvlyY, A[Lj4PdHRW]);
}
}
{
int Q5VJL1cS, e98WHCEY;
if(N==0){
e98WHCEY = 0;
}
else{
e98WHCEY = A[0];
for(Q5VJL1cS=1;Q5VJL1cS<N;Q5VJL1cS++){
e98WHCEY = max_L(e98WHCEY, A[Q5VJL1cS]);
}
}
chmax(res,e98WHCEY-KL2GvlyY);
}
}
}
return res;
}
}
;
// cLay varsion 20190721-1
// --- original code ---
// int N, A[1d6];
//
// class Solution {
// public:
// int maxAbsValExpr(vector<int>& arr1, vector<int>& arr2) {
// int i, mask, res = 0;
//
// N = arr1.size();
// rep(mask,4){
// rep(i,N) A[i] = i if[mask&1, +, -] arr1[i] if[mask&2, +, -] arr2[i];
// res >?= max(A(N)) - min(A(N));
// }
//
// return res;
// }
// };
//
// {
// // main関数を適当に処理する
// }
Current time: 2024年03月28日23時01分22秒
Last modified: 2019年07月22日08時01分19秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る
Logged in as: unknown user (not login)