Submission #1531286
Source Code Expand
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define ft first
#define sc second
typedef pair<int,int> P;
typedef pair<int,P> iP;
iP pl[2000000];
vector<P> in[2000],out[2000];
int n,m,x,a,p;
int main(){
cin >> n >> m >> x >> a >> p;ll ans2;
if(a % p == 0){
int y = ((x % p) + a) % p;
if(x <= y)
ans2 = 0;
else
ans2 = 2 * (n - 1);
cout << ans2 << endl;
}
REP(i,n){
REP(j,m){
pl[i * m + j] = iP(x,P(i,j));
x %= p;
x = (x + a) % p;
}
}
sort(pl,pl + n * m);
REP(i,n){
REP(j,m){
int k = i * m + j;
if(pl[k].sc.ft == i)
continue;
in[i].pb(P(pl[k].sc.sc,pl[k].sc.ft));
out[pl[k].sc.ft].pb(P(pl[k].sc.sc,pl[k].sc.ft));
}
}
REP(i,n){
sort(in[i].begin(),in[i].end());
sort(out[i].begin(),out[i].end());
}
ll ans = 0;
REP(i,n){
REP(j,in[i].size()){
ans += (ll)(abs(in[i][j].ft - out[i][j].ft) + abs(in[i][j].sc - out[i][j].sc));
}
}
if(a % p == 0 && ans == ans2)
return 0;
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
A - BMI |
User |
kyawakyawa |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1633 Byte |
Status |
RE |
Exec Time |
97 ms |
Memory |
384 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
All |
case_01.txt, case_02.txt, case_03.txt, case_04.txt, case_05.txt, case_06.txt, case_07.txt, case_08.txt, case_09.txt, case_10.txt, case_11.txt, case_12.txt, case_13.txt, case_14.txt, case_15.txt, case_16.txt, case_17.txt, case_18.txt |
Case Name |
Status |
Exec Time |
Memory |
case_01.txt |
RE |
95 ms |
384 KB |
case_02.txt |
RE |
96 ms |
384 KB |
case_03.txt |
RE |
95 ms |
384 KB |
case_04.txt |
RE |
97 ms |
384 KB |
case_05.txt |
RE |
95 ms |
384 KB |
case_06.txt |
RE |
96 ms |
384 KB |
case_07.txt |
RE |
95 ms |
384 KB |
case_08.txt |
RE |
95 ms |
384 KB |
case_09.txt |
RE |
96 ms |
384 KB |
case_10.txt |
RE |
96 ms |
384 KB |
case_11.txt |
RE |
96 ms |
384 KB |
case_12.txt |
RE |
96 ms |
384 KB |
case_13.txt |
RE |
96 ms |
384 KB |
case_14.txt |
RE |
97 ms |
384 KB |
case_15.txt |
RE |
96 ms |
384 KB |
case_16.txt |
RE |
96 ms |
384 KB |
case_17.txt |
RE |
96 ms |
384 KB |
case_18.txt |
RE |
96 ms |
384 KB |
sample_01.txt |
RE |
96 ms |
384 KB |
sample_02.txt |
RE |
95 ms |
384 KB |