QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722591#8994. Rhythm FlowN_z_AC ✓12ms18944kbC++236.6kb2024-11-07 19:37:442024-11-07 19:37:45

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 19:37:45]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:18944kb
  • [2024-11-07 19:37:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}

void init();void solve(int tc);
main()
{
	init();int t=1;
	// cin>>t;
	for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
void solve([[maybe_unused]]int tc)
{
	int n,m;
	cin>>n>>m;
	vector<int>a(n),b(m);
	cin>>a>>b;
	vector<vector<int>>dp(n+1,vector<int>(m+1));
	auto f=[&](int v)
	{
		if(v<=15)return 7;
		if(v<=23)return 6;
		if(v<=43)return 4;
		if(v<=102)return 2;
		return 0;
	};
	for(int x=0;x<=n;x++)
	for(int y=0;y<=m;y++)
	{
		if(y<m)dp[x][y+1]=max(dp[x][y+1],dp[x][y]);
		if(x<n)dp[x+1][y]=max(dp[x+1][y],dp[x][y]);
		if(x<n&&y<m)dp[x+1][y+1]=max(dp[x+1][y+1],dp[x][y]+f(abs(a[x]-b[y])));
	}
	// dbg(dp);
	cout<<dp[n][m]<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

3 4
100
200
300
99
201
240
323

output:

20

result:

ok single line: '20'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

4 3
1000
2000
2500
3000
1103
2598
4000

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

2 2
100
144
56
100

output:

7

result:

ok single line: '7'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

1 1
1
103

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

1 1
1000000000
999999957

output:

4

result:

ok single line: '4'

Test #6:

score: 0
Accepted
time: 10ms
memory: 18872kb

input:

2000 2000
173738194
173738195
173738196
173738197
173738198
173738199
173738200
173738201
173738202
173738203
173738204
173738205
173738206
173738207
173738208
173738209
173738210
173738211
173738212
173738213
173738214
173738215
173738216
173738217
173738218
173738219
173738220
173738221
173738222
...

output:

10829

result:

ok single line: '10829'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

1 1
1
1000000000

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 10ms
memory: 18936kb

input:

2000 2000
891052031
891052032
891052033
891052034
891052035
891052036
891052037
891052038
891052039
891052040
891052041
891052042
891052043
891052044
891052045
891052046
891052047
891052048
891052049
891052050
891052051
891052052
891052053
891052054
891052055
891052056
891052057
891052058
891052059
...

output:

10066

result:

ok single line: '10066'

Test #9:

score: 0
Accepted
time: 8ms
memory: 10964kb

input:

2000 1000
112624313
112624314
112624315
112624316
112624317
112624318
112624319
112624320
112624321
112624322
112624323
112624324
112624325
112624326
112624327
112624328
112624329
112624330
112624331
112624332
112624333
112624334
112624335
112624336
112624337
112624338
112624339
112624340
112624341
...

output:

7000

result:

ok single line: '7000'

Test #10:

score: 0
Accepted
time: 8ms
memory: 11008kb

input:

1000 2000
932372416
932372417
932372418
932372419
932372420
932372421
932372422
932372423
932372424
932372425
932372426
932372427
932372428
932372429
932372430
932372431
932372432
932372433
932372434
932372435
932372436
932372437
932372438
932372439
932372440
932372441
932372442
932372443
932372444
...

output:

7000

result:

ok single line: '7000'

Test #11:

score: 0
Accepted
time: 10ms
memory: 18940kb

input:

2000 2000
833850553
833850625
833850712
833850715
833850755
833850810
833850837
833850849
833850893
833850988
833851047
833851112
833851172
833851212
833851307
833851309
833851314
833851341
833851427
833851494
833851549
833851555
833851572
833851666
833851724
833851813
833851838
833851916
833851994
...

output:

9676

result:

ok single line: '9676'

Test #12:

score: 0
Accepted
time: 8ms
memory: 18936kb

input:

2000 2000
394928189
394928374
394928522
394928627
394928730
394928895
394928924
394929006
394929136
394929154
394929278
394929364
394929442
394929633
394929715
394929820
394930009
394930050
394930103
394930230
394930393
394930503
394930523
394930544
394930704
394930801
394930840
394931021
394931160
...

output:

7516

result:

ok single line: '7516'

Test #13:

score: 0
Accepted
time: 8ms
memory: 18860kb

input:

2000 2000
258104173
258104205
258104243
258104263
258104288
258104313
258104321
258104367
258104408
258104430
258104476
258104514
258104558
258104568
258104576
258104625
258104657
258104662
258104699
258104703
258104721
258104771
258104775
258104801
258104810
258104846
258104858
258104883
258104884
...

output:

11570

result:

ok single line: '11570'

Test #14:

score: 0
Accepted
time: 12ms
memory: 18944kb

input:

2000 2000
221886203
221886205
221886206
221886227
221886232
221886239
221886257
221886268
221886277
221886302
221886312
221886324
221886331
221886339
221886341
221886356
221886379
221886389
221886408
221886427
221886444
221886461
221886484
221886491
221886493
221886507
221886519
221886538
221886562
...

output:

12656

result:

ok single line: '12656'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

3 3
100
200
216
100
156
200

output:

15

result:

ok single line: '15'