提出詳細
ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#define FOR(i, a, b) for(int i = (a); i < (b);i++)
#define REP(i,n) for(int i = 0;i < (n);i++)
#define ALL(a) (a).begin() , (a).end()
#define DEBUG(x) cout << #x <<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
using namespace std;
const long M = 2147483647;
void solve(){
long n = 0;
long i = 0;
long total = 0;
cin >> n;
std::vector<long> x,y;
long A,B,x_i,y_i;
cin >> A >> B >> x_i >> y_i;
x.push_back(x_i);
y.push_back(y_i);
if(n == 1){
cout << 0 << endl;
return;
}
for(int i = 1;i<n;++i){
x.push_back((A*x[i-1]+B) & M);
y.push_back((A*y[i-1]+B) & M);
}
sort(ALL(x));
sort(ALL(y));
long xx = 0;
long yy = 0;
if (n % 2 == 0){
xx = x[n/2];
yy = y[n/2];
}else{
xx = x[(n+1)/2];
yy = y[(n+1)/2];
}
//DEBUG(xx);
//DEBUG(yy);
REP(i, n){
total += abs(xx - x[i]) + abs(yy - y[i]);
}
cout << total << endl;
}
int main(void){
int n = 0;
int i = 0;
cin >> n;
REP(i, n){
cout << "Case #"<< i + 1<< ":"<<endl;
solve();
}
}
提出情報
提出出力結果
テストケース情報