QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#836024 | #9916. Defeat the Enemies | ucup-team055# | WA | 32ms | 3824kb | C++23 | 11.7kb | 2024-12-28 16:08:15 | 2024-12-28 16:08:15 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
namespace{
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tuplis = array<ll, 3>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const ll LINF=0x1fffffffffffffff;
const ll MINF=0x7fffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
const int MODD=998244353;
const ld DINF=INFINITY;
const ld EPS=1e-9;
const ld PI=3.14159265358979323846;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define overload5(a,b,c,d,e,name,...) name
#define overload4(a,b,c,d,name,...) name
#define overload3(a,b,c,name,...) name
#define rep1(n) rep2(_,n)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep4(i,a,b,c) for(ll i=(a)+((b)-(a)-1)/(c)*(c);i>=(a);i-=c)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define each1(i,a) for(auto&&i:a)
#define each2(x,y,a) for(auto&&[x,y]:a)
#define each3(x,y,z,a) for(auto&&[x,y,z]:a)
#define each4(w,x,y,z,a) for(auto&&[w,x,y,z]:a)
#define each(...) overload5(__VA_ARGS__,each4,each3,each2,each1)(__VA_ARGS__)
#define all1(i) begin(i),end(i)
#define all2(i,a) begin(i),begin(i)+a
#define all3(i,a,b) begin(i)+a,begin(i)+b
#define all(...) overload3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__)
#define rall1(i) rbegin(i),rend(i)
#define rall2(i,a) rbegin(i),rbegin(i)+a
#define rall3(i,a,b) rbegin(i)+a,rbegin(i)+b
#define rall(...) overload3(__VA_ARGS__,rall3,rall2,rall1)(__VA_ARGS__)
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
#define dsum(...) accumulate(all(__VA_ARGS__),0.0L)
#define Msum(...) accumulate(all(__VA_ARGS__),mint{})
#define elif else if
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define vv(type,name,h,...) vector name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector name(h,vector(w,vector<type>(__VA_ARGS__)))
template<class T> ll sz(const T& a){ return size(a); }
template<class T, class U> ll count(const T& a, const U& b){ return count(all(a), b); }
template<class T, class F> ll count_if(const T& a, F b){ return count_if(all(a), b); }
template<class T, class F> void filter(T& a, F b){ a.erase(remove_if(all(a), not_fn(b)), a.end()); }
template<class T, class F = less<>> void sor(T& a, F b = F{}){ sort(all(a), b); }
template<class T> void rev(T& a){ reverse(all(a)); }
template<class T> void uniq(T& a){ sor(a); a.erase(unique(all(a)), end(a)); }
ll popcnt(ull a){ return __builtin_popcountll(a); }
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T> T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); }
template<class T> bool chmin(T& a, const T& b){ return a > b ? a = b, 1 : 0; }
template<class T> bool chmax(T& a, const T& b){ return a < b ? a = b, 1 : 0; }
template<class T, class U> bool chmin(T& a, const U& b){ return a > b ? a = b, 1 : 0; }
template<class T, class U> bool chmax(T& a, const U& b){ return a < b ? a = b, 1 : 0; }
vector<ll> iota(ll n, ll begin = 0){ vector<ll> a(n); iota(a.begin(), a.end(), begin); return a; }
vector<pll> factor(ull x){ vector<pll> ans; for(ull i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
vector<ll> divisor(ull x){ vector<ll> ans; for(ull i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); rrep(ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
template<class T> unordered_map<T, ll> press(vector<T> a){ uniq(a); unordered_map<T, ll> ans; rep(i, a.size()) ans[a[i]] = i; return ans; }
template<class T> auto run_press(const T& a){ vector<pair<decay_t<decltype(a[0])>, ll>> ans; each(x, a){ if(ans.empty() || ans.back().first != x) ans.emplace_back(x, 1); else ans.back().second++; } return ans; }
template<class... Ts> void in(Ts&... t);
[[maybe_unused]] void print(){}
template<class T, class... Ts> void print(const T& t, const Ts&... ts);
template<class... Ts> void out(const Ts&... ts){ print(ts...); cout << '\n'; }
namespace IO{
#define VOID(a) decltype(void(a))
struct S{ S(){ cin.tie(nullptr)->sync_with_stdio(0); fixed(cout).precision(12); } }S;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){ in(get<idx>(t)...); }
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ ituple(t, make_index_sequence<tuple_size<T>::value>{}); }
template<class T> void o(const T& t){ o(t, P<4>{}); }
template<size_t N> void o(const char (&t)[N], P<4>){ cout << t; }
template<class T, size_t N> void o(const T (&t)[N], P<3>){ o(t[0]); for(size_t i = 1; i < N; i++){ o(' '); o(t[i]); } }
template<class T> auto o(const T& t, P<2>) -> VOID(cout << t){ cout << t; }
template<class T> auto o(const T& t, P<1>) -> VOID(begin(t)){ bool first = 1; for(auto&& x : t) { if(first) first = 0; else o(' '); o(x); } }
template<class T, size_t... idx> void otuple(const T& t, index_sequence<idx...>){ print(get<idx>(t)...); }
template<class T> auto o(T& t, P<0>) -> VOID(tuple_size<T>{}){ otuple(t, make_index_sequence<tuple_size<T>::value>{}); }
#undef VOID
}
#define unpack(a) (void)(0 + ... + (a, 0))
template<class... Ts> void in(Ts&... t){ unpack(IO::i(t)); }
template<class T, class... Ts> void print(const T& t, const Ts&... ts){ IO::o(t); unpack(IO::o((cout << ' ', ts))); }
#undef unpack
#ifdef DEBUG
ll __lg(ull x){ return 63 - __builtin_clzll(x); }
#define debug(...) { print(#__VA_ARGS__); print(":"); out(__VA_ARGS__); }
#else
#define debug(...) void(0)
#endif
#define YESNO(yes,no) void yes(bool i = 1){ out(i?#yes:#no); } void no(){ out(#no); }
YESNO(first, second)
YESNO(First, Second)
YESNO(Yes, No)
YESNO(YES, NO)
YESNO(possible, impossible)
YESNO(Possible, Impossible)
YESNO(POSSIBLE, IMPOSSIBLE)
template<uint32_t m> class static_modint {
using mint = static_modint;
uint32_t _v = 0;
static const bool prime;
static constexpr pair<int32_t, int32_t> inv_gcd(int32_t a, int32_t b) {
if (a == 0) return {b, 0};
int32_t s = b, t = a, m0 = 0, m1 = 1;
while (t) {
const int32_t u = s / t;
s -= t * u;
m0 -= m1 * u;
swap(s, t);
swap(m0, m1);
}
if (m0 < 0) m0 += b / s;
return {s, m0};
}
public:
static constexpr mint raw(uint32_t v) {
mint a;
a._v = v;
return a;
}
constexpr static_modint() {}
template<class T>
constexpr static_modint(T v) {
static_assert(is_integral_v<T>, "T is not integral type.");
if constexpr (is_signed_v<T>) {
int64_t x = int64_t(v % int64_t(m));
if (x < 0) x += m;
_v = uint32_t(x);
} else _v = uint32_t(v % m);
}
static constexpr uint32_t mod() { return m; }
constexpr uint32_t val() const { return _v; }
constexpr mint& operator++() { return *this += 1; }
constexpr mint& operator--() { return *this -= 1; }
constexpr mint operator++(int) {
mint res = *this;
++*this;
return res;
}
constexpr mint operator--(int) {
mint res = *this;
--*this;
return res;
}
constexpr mint& operator+=(mint rhs) {
if (_v >= m - rhs._v) _v -= m;
_v += rhs._v;
return *this;
}
constexpr mint& operator-=(mint rhs) {
if (_v < rhs._v) _v += m;
_v -= rhs._v;
return *this;
}
constexpr mint& operator*=(mint rhs) { return *this = *this * rhs; }
constexpr mint& operator/=(mint rhs) { return *this *= rhs.inv(); }
constexpr mint operator+() const { return *this; }
constexpr mint operator-() const { return mint{} - *this; }
constexpr mint pow(long long n) const {
assert(0 <= n);
if (n == 0) return 1;
mint x = *this, r = 1;
while (1) {
if (n & 1) r *= x;
n >>= 1;
if (n == 0) return r;
x *= x;
}
}
constexpr mint inv() const {
if (prime) {
assert(_v);
return pow(m - 2);
} else {
auto eg = inv_gcd(_v, m);
assert(eg.first == 1);
return eg.second;
}
}
friend constexpr mint operator+(mint lhs, mint rhs) { return lhs += rhs; }
friend constexpr mint operator-(mint lhs, mint rhs) { return lhs -= rhs; }
friend constexpr mint operator*(mint lhs, mint rhs) { return uint64_t(lhs._v) * rhs._v; }
friend constexpr mint operator/(mint lhs, mint rhs) { return lhs /= rhs; }
friend constexpr bool operator==(mint lhs, mint rhs) { return lhs._v == rhs._v; }
friend constexpr bool operator!=(mint lhs, mint rhs) { return lhs._v != rhs._v; }
};
template<uint32_t m> constexpr bool static_modint<m>::prime = []() -> bool {
using mint = static_modint<m>;
if (m == 1) return 0;
if (m == 2 || m == 7 || m == 61) return 1;
if (m % 2 == 0) return 0;
uint32_t d = m - 1;
while (d % 2 == 0) d /= 2;
for (uint32_t a : {2, 7, 61}) {
uint32_t t = d;
mint y = mint(a).pow(t);
while (t != m - 1 && y != 1 && y != m - 1) {
y *= y;
t <<= 1;
}
if (y != m - 1 && t % 2 == 0) return 0;
}
return 1;
}();
using mint = static_modint<MOD>;
istream& operator>>(istream& in, mint& x) { long long a; in >> a; x = a; return in; }
ostream& operator<<(ostream& out, mint x) { return out << x.val(); }
constexpr mint operator""_M(unsigned long long x) { return x; }
struct T{
ll x = LINF;
mint cnt = 0;
};
void operator+=(T& a, T b) {
if (a.x == b.x) a.cnt += b.cnt;
else if (a.x > b.x) a = b;
}
T operator+(T a, ll b) {
a.x += b;
return a;
}
void solve(){
LL(n,m);
VEC(ll,a,n);
VEC(ll,b,n);
LL(k);
VEC(ll,c,k);
c.insert(begin(c),0);
ll mx=0;
rep(i,n)chmax(mx,a[i]+b[i]);
T ans;
rep(S,mx,mx+k+k){
vector<T> dp(S+1);
vector<ll> R(S+1,S);
rep(i,n)chmin(R[b[i]-1],S-a[i]);
rrep(i,S)chmin(R[i],R[i+1]);
rep(i,S)chmin(R[i],i+k);
dp[0]={0,1};
rep(i,S)rep(j,i+1,R[i]+1)dp[j]+=dp[i]+c[j-i];
ans+=dp[S];
}
out(ans.x,ans.cnt);
}
}
int main(){
ll t = 1;
in(t);
rep(i,t){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
4 5 5 3 5 2 1 2 3 1 3 2 3 3 2 3 4 3 2 2 2 2 2 2 2 3 2 3 3 7 6 5 3 4 6 6 3 4 4 6 4 2 3 5 5 4 2 4 6 7 10 100 38 49 79 66 49 89 21 55 13 23 67 56 26 39 56 16 84 50 92 82 11 6 6 7 8 9 9 9 9 9 9 9
output:
9 1 6 4 18 18 99 44387
result:
ok 8 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
1000 5 3 1 1 3 1 2 3 2 1 1 2 1 5 5 3 3 3 2 2 1 1 1 3 1 1 3 3 1 3 5 5 4 3 5 1 4 5 5 2 5 5 2 1 5 5 5 5 5 5 5 4 2 1 2 4 1 2 1 1 5 3 2 1 2 1 1 1 3 2 1 1 1 5 2 1 1 1 1 1 3 2 2 1 5 5 2 3 5 2 2 5 2 4 3 1 2 3 3 5 1 1 1 1 1 1 1 1 1 1 1 3 5 4 4 5 4 1 4 4 4 2 4 3 1 3 3 1 2 1 5 2 2 3 4 2 4 1 5 4 5 1 4 2 5 1 5 1...
output:
20 1 3 1 9 1 5 4 20 1 2 1 15 4 8 4 14 1 4 1 36 1 12 1 27 1 2 1 20 1 4 1 10 1 23 1 10 1 4 1 28 1 4 1 5 1 4 1 6 1 8 1 6 1 16 1 9 6 5 1 30 1 4 1 4 1 2 1 35 1 10 1 2 1 4 1 15 6 4 1 20 1 4 1 6 1 40 1 4 1 18 1 8 1 7 1 6 1 2 1 10 1 3 1 9 1 8 1 4 1 6 4 20 1 8 2 10 1 2 1 2 1 50 1 24 1 6 1 10 16 10 1 6 1 3 1 ...
result:
ok 2000 numbers
Test #3:
score: -100
Wrong Answer
time: 32ms
memory: 3824kb
input:
200 50 16 15 15 15 14 15 13 15 15 14 15 16 16 16 12 16 16 16 16 14 13 14 16 13 16 13 16 14 13 16 16 12 14 16 15 13 16 14 16 12 15 14 15 13 14 15 15 15 15 16 13 13 14 16 13 16 16 16 15 13 15 13 16 15 15 16 16 16 16 16 15 16 16 14 12 15 16 16 16 13 12 15 15 16 12 15 14 16 16 16 12 16 16 16 16 15 14 15...
output:
14 6889 68 33856 60 841 388 14400 20 214369 100 1 72 8281 6 256 39 30 4 1 58 1 12 144 4 144 116 169 46 38416 100 1 26 11025 88 36 80 1 10 81 114 100 92 225562693 56 1 50 1296 400 266906773 68 1 32 9 6 1 1100 1 100 239672455 46 1600 80 57 44 576 92 1 26 441 7 320 106 9 68 29241 34 324 29 7878 4 1 4 1...
result:
wrong answer 44th numbers differ - expected: '413318192', found: '225562693'