QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#772466 | #5146. Skills | songszh | ML | 0ms | 0kb | C++14 | 3.9kb | 2024-11-22 19:42:42 | 2024-11-22 19:42:42 |
answer
#include <bits/stdc++.h>
// #define int long long
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define rep(i,l,r) for (int i = (int)(l); i <= (int)(r); ++ i )
#define rep1(i,l,r) for (int i = (int)(l); i >= (int)(r); -- i )
#define il inline
#define fst first
#define snd second
#define ptc putchar
#define Yes ptc('Y'),ptc('e'),ptc('s'),puts("")
#define No ptc('N'),ptc('o'),puts("")
#define YES ptc('Y'),ptc('E'),ptc('S'),puts("")
#define NO ptc('N'),ptc('O'),puts("")
#define pb emplace_back
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define get(x) ((x - 1) / len + 1)
#define debug() puts("------------")
using namespace std;
typedef pair<int,int> PII;
typedef pair<int,PII> PIII;
typedef pair<ll,ll> PLL;
namespace szhqwq {
template<class T> il void read(T &x) {
x = 0; T f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
x *= f;
}
template<class T,class... Args> il void read(T &x,Args &...x_) { read(x); read(x_...); }
template<class T> il void print(T x) {
if (x < 0) ptc('-'), x = -x;
if (x > 9) print(x / 10); ptc(x % 10 + '0');
}
template<class T,class T_> il void write(T x,T_ ch) { print(x); ptc(ch); }
template<class T,class T_> il void chmax(T &x,T_ y) { x = max(x,y); }
template<class T,class T_> il void chmin(T &x,T_ y) { x = min(x,y); }
template<class T,class T_,class T__> il T qmi(T a,T_ b,T__ p) {
T res = 1; while (b) {
if (b & 1) res = res * a % p;
a = a * a % p; b >>= 1;
} return res;
}
template<class T> il T gcd(T a,T b) { if (!b) return a; return gcd(b,a % b); }
template<class T,class T_> il void exgcd(T a, T b, T_ &x, T_ &y) {
if (b == 0) { x = 1; y = 0; return; }
exgcd(b,a % b,y,x); y -= a / b * x; return ;
}
template<class T,class T_> il T getinv(T x,T_ p) { T inv,y; exgcd(x,(T)p,inv,y); inv = (inv + p) % p; return inv; }
} using namespace szhqwq;
const int N = 1010,inf = 1e9,mod = 998244353;
const ull base = 131,base_ = 233;
const ll inff = 1e18;
int n,a[N][3];
int f[N][210][210],g[N][210][210],h[N][210][210];
il int p(int x) {
return !x ? x : x + 1;
}
il void solve() {
//------------code------------
read(n);
rep(i,1,n) read(a[i][0],a[i][1],a[i][2]);
memset(f,-1,sizeof f); memset(g,-1,sizeof g); memset(h,-1,sizeof h);
f[0][0][0] = g[0][0][0] = h[0][0][0] = 0;
rep(i,0,n - 1)
rep(j,0,min(200,n))
rep(k,0,min(200,n)) {
if (~f[i][j][k]){
chmax(f[i + 1][p(j)][p(k)],f[i][j][k] + a[i + 1][0] - p(j) - p(k));
chmax(g[i + 1][1][p(k)],f[i][j][k] + a[i + 1][1] - p(k) - 1);
chmax(h[i + 1][1][p(k)],f[i][j][k] + a[i + 1][2] - p(k) - 1);
}
if (~g[i][j][k]) {
chmax(f[i + 1][1][p(k)],g[i][j][k] + a[i + 1][0] - 1 - p(k));
chmax(g[i + 1][p(j)][p(k)],g[i][j][k] + a[i + 1][1] - p(j) - p(k));
chmax(h[i + 1][p(j)][1],g[i][j][k] + a[i + 1][2] - p(j) - 1);
}
if (~h[i][j][k]) {
chmax(f[i + 1][1][p(k)],h[i][j][k] + a[i + 1][0] - 1 - p(k));
chmax(g[i + 1][p(j)][1],h[i][j][k] + a[i + 1][1] - p(j) - 1);
chmax(h[i + 1][p(j)][p(k)],h[i][j][k] + a[i + 1][2] - p(j) - p(k));
}
}
int ret = 0;
rep(j,0,min(200,n)) rep(k,0,min(200,n)) chmax(ret,max({f[n][j][k],g[n][j][k],h[n][j][k]}));
write(ret,'\n');
return ;
}
il void init() {
return ;
}
signed main() {
// init();
int _ = 1;
read(_);
while (_ -- ) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Memory Limit Exceeded
input:
2 3 1 1 10 1 10 1 10 1 1 5 1 2 3 6 5 4 7 8 9 12 11 10 13 14 15
output:
26 41