Submission #65027832


Source Code Expand

//ANMHLIJKTJIY!
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define F first
#define S second
#define ll long long
#define N 25
using namespace std;
int n,m,a[N][N],pw10[100];
vector<int> v0[N][N],v1[N][N];
int main(){
	cin>>n>>m;
	pw10[0]=1;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
	for(int i=1;i<100;i++) pw10[i]=(10ll*pw10[i-1])%m;
	for(int i=0;i<(1<<(n-1));i++){
		int v=0,x=0,y=0;
		for(int j=0;j<n-1&&x<n&&y<n;j++){
			v=(10ll*v+a[x][y])%m;
			if((i>>j)&1) x++;
			else y++;
		}
		if(x<n&&y<n) v0[x][y].push_back((1ll*v*pw10[n])%m);
	}
	for(int i=0;i<(1<<(n-1));i++){
		int v=a[n-1][n-1],x=n-1,y=n-1;
		for(int j=0;j<n-1&&x>=0&&y>=0;j++){
			if((i>>j)&1) x--;
			else y--;
			v=(1ll*v+1ll*a[x][y]*pw10[j+1])%m;
		}
		if(x>=0&&y>=0) v1[x][y].push_back(v);
	}
	int ans=0;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) if((!v0[i][j].empty())&&(!v1[i][j].empty())){
		sort(v0[i][j].begin(),v0[i][j].end());
		sort(v1[i][j].begin(),v1[i][j].end());
		for(int x=v0[i][j].size()-1,y=0;x>=0;x--){
			while(y<v1[i][j].size()&&v1[i][j][y]+v0[i][j][x]<m) y++;
			if(y) ans=max(ans,v1[i][j][y-1]+v0[i][j][x]);
			ans=max(ans,v1[i][j].back()+v0[i][j][x]-m);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Submission Info

Submission Time
Task F - Path to Integer
User qiuzx_
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1628 Byte
Status AC
Exec Time 143 ms
Memory 8752 KiB

Compile Error

Main.cpp:5:30: warning: ‘-fwhole-program’ is not an option that controls warnings [-Wpragmas]
    5 | #pragma GCC diagnostic error "-fwhole-program"
      |                              ^~~~~~~~~~~~~~~~~
Main.cpp:6:30: warning: ‘-fcse-skip-blocks’ is not an option that controls warnings [-Wpragmas]
    6 | #pragma GCC diagnostic error "-fcse-skip-blocks"
      |                              ^~~~~~~~~~~~~~~~~~~
Main.cpp:7:30: warning: ‘-funsafe-loop-optimizations’ is not an option that controls warnings [-Wpragmas]
    7 | #pragma GCC diagnostic error "-funsafe-loop-optimizations"
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:48:32: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   48 |                         while(y<v1[i][j].size()&&v1[i][j][y]+v0[i][j][x]<m) y++;
      |                               ~^~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 44
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3836 KiB
00_sample_01.txt AC 1 ms 3724 KiB
00_sample_02.txt AC 1 ms 3772 KiB
01_handmade_00.txt AC 1 ms 3680 KiB
01_handmade_01.txt AC 1 ms 3632 KiB
01_handmade_02.txt AC 1 ms 3720 KiB
01_handmade_03.txt AC 1 ms 3688 KiB
01_handmade_04.txt AC 1 ms 3700 KiB
01_handmade_05.txt AC 4 ms 3836 KiB
01_handmade_06.txt AC 107 ms 8476 KiB
01_handmade_07.txt AC 100 ms 8492 KiB
01_handmade_08.txt AC 103 ms 8696 KiB
01_handmade_09.txt AC 101 ms 8672 KiB
01_handmade_10.txt AC 1 ms 3816 KiB
01_handmade_11.txt AC 2 ms 3820 KiB
01_handmade_12.txt AC 121 ms 8664 KiB
01_handmade_13.txt AC 141 ms 8580 KiB
01_handmade_14.txt AC 102 ms 8668 KiB
01_handmade_15.txt AC 101 ms 8584 KiB
02_random_00.txt AC 1 ms 3724 KiB
02_random_01.txt AC 1 ms 3744 KiB
02_random_02.txt AC 1 ms 3852 KiB
02_random_03.txt AC 2 ms 3868 KiB
02_random_04.txt AC 1 ms 3764 KiB
02_random_05.txt AC 1 ms 3712 KiB
02_random_06.txt AC 1 ms 3860 KiB
02_random_07.txt AC 2 ms 3724 KiB
02_random_08.txt AC 17 ms 4204 KiB
02_random_09.txt AC 1 ms 3708 KiB
02_random_10.txt AC 139 ms 8480 KiB
02_random_11.txt AC 140 ms 8488 KiB
02_random_12.txt AC 139 ms 8588 KiB
02_random_13.txt AC 140 ms 8752 KiB
02_random_14.txt AC 140 ms 8680 KiB
02_random_15.txt AC 141 ms 8692 KiB
02_random_16.txt AC 139 ms 8700 KiB
02_random_17.txt AC 139 ms 8532 KiB
02_random_18.txt AC 140 ms 8488 KiB
02_random_19.txt AC 143 ms 8676 KiB
02_random_20.txt AC 140 ms 8656 KiB
02_random_21.txt AC 140 ms 8476 KiB
02_random_22.txt AC 139 ms 8492 KiB
02_random_23.txt AC 140 ms 8480 KiB
02_random_24.txt AC 139 ms 8676 KiB