結果
| 問題 |
No.60 魔法少女
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-01 21:04:26 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 7,099 bytes |
| コンパイル時間 | 3,293 ms |
| コンパイル使用メモリ | 258,020 KB |
| 実行使用メモリ | 21,248 KB |
| 最終ジャッジ日時 | 2024-09-28 10:32:44 |
| 合計ジャッジ時間 | 6,087 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | WA * 10 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:234:18: warning: narrowing conversion of 'y' from 'll' {aka 'long long int'} to 'long unsigned int' [-Wnarrowing]
234 | {y,x},
| ^
main.cpp:234:20: warning: narrowing conversion of 'x' from 'll' {aka 'long long int'} to 'long unsigned int' [-Wnarrowing]
234 | {y,x},
| ^
main.cpp:235:26: warning: narrowing conversion of '(long long int)std::min<long long int>(((y + h) + 1), 1000)' from 'long long int' to 'long unsigned int' [-Wnarrowing]
235 | {std::min(y+h+1,1000ll),std::min(x+w+1,1000ll)}
| ~~~~~~~~^~~~~~~~~~~~~~
main.cpp:235:49: warning: narrowing conversion of '(long long int)std::min<long long int>(((x + w) + 1), 1000)' from 'long long int' to 'long unsigned int' [-Wnarrowing]
235 | {std::min(y+h+1,1000ll),std::min(x+w+1,1000ll)}
| ~~~~~~~~^~~~~~~~~~~~~~
ソースコード
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){return*istream_iterator<T>(is);}
template<class T=ll,template<class,class>class Container=vector,template<class>class Allocator=allocator>inline Container<T,Allocator<T>>ins(istream&is=cin){return{istream_iterator<T>(is),istream_iterator<T>()};}
template<class Container>concept pushbackable=requires(Container&c){c.push_back(declval<typename Container::value_type>());};
template<class Container>concept reservable=requires(Container&c){c.reserve();};
template<class T=ll,template<class,class>class Container=vector,template<class>class Allocator=allocator>requires pushbackable<Container<T,Allocator<T>>>inline Container<T,Allocator<T>>ins(size_t n,istream&is=cin){Container<T,Allocator<T>>c;if constexpr(reservable<decltype(c)>)c.reserve(n);copy_n(istream_iterator<T>(is),n,back_inserter(c));return c;}
template<class T>inline bool chmin(T&a,T b){return a>b?a=b,true:false;}
template<class T>inline bool chmax(T&a,T b){return a<b?a=b,true:false;}
template<class T,class...Sizes>inline auto multdim_vector_v(T v,size_t size,Sizes...sizes){if constexpr(sizeof...(Sizes)==0)return vector(size,v);else return vector(size,multdim_vector_v(v,sizes...));}
template<class T,class...Sizes>inline auto multdim_vector(Sizes...sizes){return multdim_vector_v(T{},sizes...);}
template <class T, size_t Dimension>
class cyclic_imos final : private std::vector<cyclic_imos<T, Dimension - 1>> {
friend cyclic_imos<T, Dimension + 1>;
public:
using coordinate = std::array<std::size_t, Dimension>;
struct segment {
coordinate begin, end;
};
constexpr inline static std::size_t dimension = Dimension;
using std::vector<cyclic_imos<T, Dimension - 1>>::begin;
using std::vector<cyclic_imos<T, Dimension - 1>>::end;
using std::vector<cyclic_imos<T, Dimension - 1>>::operator[];
private:
using std::vector<cyclic_imos<T, Dimension - 1>>::size;
T& get(const std::span<const std::size_t, Dimension> idxs)
{
return (*this)[idxs.front()].get(idxs.template last<Dimension - 1>());
}
void set(
const std::span<const std::size_t, Dimension> begin,
const std::span<const std::size_t, Dimension> end,
const T weight
)
{
(*this)[begin.front()].set(
begin.template last<Dimension - 1>(),
end.template last<Dimension - 1>(),
weight
);
(*this)[end.front()].set(
begin.template last<Dimension - 1>(),
end.template last<Dimension - 1>(),
-weight
);
}
cyclic_imos<T, Dimension> &operator+=(const cyclic_imos<T, Dimension> &ci)
{
for (std::size_t i = 0; i < size(); ++i) {
(*this)[i] += ci[i];
}
return *this;
}
public:
template <class... Sizes>
cyclic_imos(const std::size_t size, const Sizes... sizes)
: std::vector<cyclic_imos<T, Dimension - 1>>(
size + 1,
cyclic_imos<T, sizeof...(Sizes)>(sizes...)
)
{
}
T& get(const coordinate &c)
{
return get(std::span{c});
}
void set(const segment &s, const T weight)
{
set(std::span{s.begin}, std::span{s.end}, weight);
}
void set_cyclic(const segment &s, const T weight)
{
set(s, weight);
for (unsigned i = 1; i < (1 << Dimension); ++i) {
segment correction;
for (unsigned j = 0; j < Dimension; ++j) {
if (i & (1 << j)) {
if (s.begin[j] <= s.end[j]) {
goto CONTINUE;
}
correction.begin[j] = 0;
correction.end[j] = size() - 1;
} else {
correction.begin[j] = s.begin[j];
correction.end[j] = s.end[j];
}
}
set(correction, weight);
CONTINUE:
;
}
}
void accumulate()
{
for (std::size_t i = 0; i < size() - 1; ++i) {
(*this)[i + 1] += (*this)[i];
}
for (auto &child : *this) {
child.accumulate();
}
}
};
template <class T>
class cyclic_imos<T, 1> final : private std::vector<T> {
friend cyclic_imos<T, 2>;
public:
using coordinate = std::array<std::size_t, 1>;
struct segment {
coordinate begin, end;
};
constexpr inline static std::size_t dimension = 1;
using std::vector<T>::begin;
using std::vector<T>::end;
using std::vector<T>::operator[];
private:
using std::vector<T>::size;
T& get(const std::span<const std::size_t, 1> idxs)
{
return (*this)[idxs.front()];
}
void set(
const std::span<const std::size_t, 1> begin,
const std::span<const std::size_t, 1> end,
const T weight
)
{
(*this)[begin.front()] += weight;
(*this)[end.front()] -= weight;
}
cyclic_imos<T, 1> &operator+=(const cyclic_imos<T, 1> &ci)
{
for (std::size_t i = 0; i < size(); ++i) {
(*this)[i] += ci[i];
}
return *this;
}
public:
cyclic_imos(const std::size_t size)
: std::vector<T>(size + 1)
{
}
T& get(const coordinate &c)
{
return (*this)[c.front()];
}
T& get(const std::size_t idx)
{
return (*this)[idx];
}
void set(const segment &s, const T weight)
{
set(std::span{s.begin}, std::span{s.end}, weight);
}
void set(const size_t begin, const size_t end, const T weight)
{
set({.begin = begin, .end = end}, weight);
}
void set_cyclic(const segment &s, const T weight)
{
set(s, weight);
if (s.begin.front() > s.end.front()) {
(*this).front() += weight;
(*this).back() -= weight;
}
}
void set_cyclic(const std::size_t begin, const std::size_t end, const T weight)
{
set_cyclic({.begin = begin, .end = end}, weight);
}
void accumulate()
{
for (std::size_t i = 0; i < size() - 1; ++i) {
(*this)[i + 1] += (*this)[i];
}
}
};
template <class T>
auto make_cyclic_imos(auto... sizes)
{
return cyclic_imos<T, sizeof...(sizes)>(sizes...);
}
int main()
{
struct enemy{
ll x,y,hp;
};
ll n=in(),k=in();
vector<enemy>enemies(n);
for(ll i=0;i<n;++i){
ll x=in(),y=in(),hp=in();
enemies[i]={x+500,y+500,hp};
}
auto imos=make_cyclic_imos<ll>(1000,1000);
for(ll i=0;i<k;++i){
ll x=in(),y=in(),w=in(),h=in(),d=in();
x+=500;
y+=500;
imos.set(
{
{y,x},
{std::min(y+h+1,1000ll),std::min(x+w+1,1000ll)}
},
d
);
}
imos.accumulate();
cout<<accumulate(
enemies.begin(),enemies.end(), 0ll,
[imos](ll acc,const auto&e){
return acc+std::max(0ll,e.hp-imos[e.y][e.x]);
}
)<<endl;
}