Submission #54596528
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pii> vii;
#define INF 10000000000000000
#define inf 1000000000
// #define MOD 1000000007
// #define MOD 672804213107214
// #define MOD 998244353
#define PI 3.1415926535897932385
#define pb push_back
#define bitc __builtin_popcountll
#define mp make_pair
#define all(ar) ar.begin(), ar.end()
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it, ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar, val) memset(ar, val, sizeof(ar)) // 0x3f for inf, 0x80 for -INF can also use with pairs
#define print(a) for(auto x : a) cout << x << " "; cout << endl
#define print1(a) for(auto x : a) cout << x.first << " " << x.second << endl
#define print2(a,x,y) for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
#define bug(...) __f (#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
const char* comma = strchr (names + 1, ',');
cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
void solve()
{
//vector<int> sieve(N+1,0); //fill constructor
//primeSieve(sieve);
ll h,w,k;
cin>>h>>w>>k;
ll x,y;
cin>>x>>y;
ll k2=k;
ll n=h;
ll m=w;
ll arr[h][w];
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
cin>>arr[i][j];
}
queue<pair<ll,ll>>q;
vector<vector<ll>>dp2(h*w,vector<ll>(2500,-1));
dp2[(x-1)*w+(y-1)][0]=0;
ll maxn=0;
for(int k1=1;k1<=min(k,2500LL);k1++)
{
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
vector<pair<ll,ll>>vec={{0,0},{-1,0},{0,1},{1,0},{0,-1}};
for(int k=0;k<vec.size();k++)
{
ll x1=vec[k].first;
ll y1=vec[k].second;
if(i+x1>=0&&(i+x1<n)&&(j+y1)>=0&&(j+y1)<m)
{
if(dp2[(i+x1)*w+j+y1][k1-1]!=-1)
{
dp2[i*w+j][k1]=max(dp2[i*w+j][k1],dp2[(i+x1)*w+j+y1][k1-1]+arr[i][j]);
maxn=max(maxn,dp2[i*w+j][k1]+(k2-k1)*(arr[i][j]));
// cout<<arr[i][j]<<" "<<k-k1<<" "<<i<<" "<<j<<"\n";
}
}
}
}
}
}
cout<<maxn;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0), cout.precision(15); cout<<fixed;
int t=1;
// cin>>t;
while(t--)
{
solve();
}
}
Submission Info
Submission Time
2024-06-15 13:01:23
Task
G - AtCoder Tour
User
SanathSalampuria
Language
C++ 20 (gcc 12.2)
Score
550
Code Size
3185 Byte
Status
AC
Exec Time
279 ms
Memory
52312 KB
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:68:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
68 | for(int k=0;k<vec.size();k++)
| ~^~~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
550 / 550
Status
Set Name
Test Cases
Sample
sample00.txt, sample01.txt
All
sample00.txt, sample01.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt
Case Name
Status
Exec Time
Memory
sample00.txt
AC
1 ms
3720 KB
sample01.txt
AC
1 ms
3600 KB
testcase00.txt
AC
1 ms
3520 KB
testcase01.txt
AC
274 ms
52124 KB
testcase02.txt
AC
279 ms
52072 KB
testcase03.txt
AC
76 ms
18580 KB
testcase04.txt
AC
23 ms
52180 KB
testcase05.txt
AC
22 ms
52180 KB
testcase06.txt
AC
153 ms
52228 KB
testcase07.txt
AC
153 ms
52224 KB
testcase08.txt
AC
158 ms
52220 KB
testcase09.txt
AC
272 ms
52104 KB
testcase10.txt
AC
76 ms
52272 KB
testcase11.txt
AC
30 ms
34496 KB
testcase12.txt
AC
274 ms
52312 KB
testcase13.txt
AC
254 ms
49048 KB
testcase14.txt
AC
124 ms
52104 KB
testcase15.txt
AC
163 ms
44208 KB
testcase16.txt
AC
273 ms
52312 KB
testcase17.txt
AC
122 ms
28664 KB
testcase18.txt
AC
97 ms
52072 KB
testcase19.txt
AC
20 ms
18620 KB
testcase20.txt
AC
272 ms
52144 KB
testcase21.txt
AC
113 ms
26784 KB
testcase22.txt
AC
221 ms
52312 KB
testcase23.txt
AC
55 ms
29228 KB
testcase24.txt
AC
275 ms
52128 KB
testcase25.txt
AC
96 ms
22912 KB
testcase26.txt
AC
270 ms
52212 KB
testcase27.txt
AC
16 ms
17896 KB
testcase28.txt
AC
274 ms
52128 KB
testcase29.txt
AC
72 ms
18336 KB
testcase30.txt
AC
150 ms
52216 KB
testcase31.txt
AC
179 ms
44660 KB
testcase32.txt
AC
274 ms
52236 KB
testcase33.txt
AC
141 ms
31828 KB