QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682681#5301. Modulo Ruins the LegendabsabsWA 3ms6492kbC++233.8kb2024-10-27 16:56:302024-10-27 16:56:30

Judging History

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

  • [2024-10-27 16:56:30]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:6492kb
  • [2024-10-27 16:56:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ms(x, y) memset(x, y, sizeof x);
#define debug(x) cout << #x << " = " << x << endl;
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define fre                           \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const double esp = 1e-6;
const ull MOD1 = 1610612741;
const ull MOD2 = 805306457;
const ull BASE1 = 1331;
const ull BASE2 = 131;
#define pre(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
char *p1, *p2, buf[100000]; // 快读和同步流二者只能选一个
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
int read()
{
	int x = 0, f = 1;
	char ch = nc();
	while (ch < 48 || ch > 57)
	{
		if (ch == '-')
			f = -1;
		ch = nc();
	}
	while (ch >= 48 && ch <= 57)
		x = x * 10 + ch - 48, ch = nc();
	return x * f;
}
void write(int x)
{
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}
int n,m;
int a[N];
int exgcd(int a,int b,int &x,int &y)//扩展欧几里得算法 ,求出来的结果是方程变换后右值等于 gcd 的系数 x y
{
	if(b == 0)
	{
		x = 1ll,y = 0;
		return a;
	}
	int ret = exgcd(b,a%b,y,x);
	y -= a / b * x;
	return ret;
}
void solve()
{
	cin >> n >> m;
    int sum = 0;
    pre(i,1,n) cin >> a[i],sum += a[i];
    sum %= m;
    int d1 = __gcd(n * (n + 1) / 2ll,n);
    int d2 = __gcd(d1,m);
    int x1 = 0,y1 = 0;
    exgcd(n,n * (n + 1) / 2ll,x1,y1);
    x1 = (x1 % m + m) % m,y1 = (y1 % m + m) % m;


    int x2 = 0,y2 = 0;
    exgcd(d1,m,x2,y2);
    x2 = (x2 % m + m) % m;


    int k = -sum / d2;
    int x = (x1 % m * x2 % m * k % m + m) % m;
    int yyyyyyy = (y1 % m * x2 % m * k % m + m) % m;
    // int tpx = x1 * x / d1;
    // int tpy = y1 * yyyyyyy / d1;
    // int ans = ((tpx % m * (n * (n + 1) / 2 % m) % m) + (tpy * n % m) + yyyyyyy * m % m + sum + m) % m ;
    int ans = (x * d1 % d2 + yyyyyyy * m % d2 - sum / d2 + 2 * d2) % d2 ;
    cout << ans << "\n" << x << " " << yyyyyyy << endl;








    // sum %= m;
    // int d1 = __gcd(n * (n + 1) / 2,n);
    // int d2 = n * (n + 1) / 2,d3 = n;
    // if(sum == 0)
    // {
    //     cout << 0 << "\n" << "0 0" << endl;
    //     return ;
    // }
    // sum = m - sum;
    // if(sum % d1 == 0)
    // {
    //     cout << 0 << endl << 1 << endl << 1 << endl;
    //     return ;
    // }
    // int ans = inf;
    // pre(i,0,2 * d1)
    // {
    //     if((sum + i) % d1 == 0)
    //     {
    //         ans = min(ans,(sum + i) % sum);
    //         // cout << i << endl;
    //         // return ;
    //     }
    // }
        

    // int x = 0,y = 0;
    // //现在 的数据是 sum + ans
    // exgcd(n * (n + 1) / 2,n,x,y);
    // //求出来的结果是 右 = d 时的结果
    // int tpa = (n * (n + 1) / 2) / d1,tpb = n / d1;
    // x = x + (sum + ans + m) / d1 * tpa,y= y + (sum + ans + m) / d1 * tpb;

    
   
    // x = (x + m) % m;
    // y = (y + m) % m ;
    // cout << ans << "\n" << x << " " << y << endl;


}
// #define LOCAL
signed main()
{
	ios
	// fre
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	auto start = std::chrono::high_resolution_clock::now();
#endif
	
	int t = 1;
	// cin >> t;
	while (t--)
		solve();
	
#ifdef LOCAL
	auto end = std::chrono::high_resolution_clock::now();
	cout << "Execution time: "
	<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
	<< " ms" << '\n';
#endif
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 24
1 1 4 5 1 4

output:

1
15 19

result:

ok ok

Test #2:

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

input:

7 29
1 9 1 9 8 1 0

output:

0
0 0

result:

ok ok

Test #3:

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

input:

1 1
0

output:

0
0 0

result:

ok ok

Test #4:

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

input:

1 1000000000
963837005

output:

0
0 36162995

result:

ok ok

Test #5:

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

input:

2 1
0 0

output:

0
0 0

result:

ok ok

Test #6:

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

input:

2 1000000000
948507269 461613424

output:

0
410120693 589879307

result:

ok ok

Test #7:

score: 0
Accepted
time: 3ms
memory: 5892kb

input:

100000 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0
0 0

result:

ok ok

Test #8:

score: -100
Wrong Answer
time: 3ms
memory: 6492kb

input:

100000 1000000000
253614966 278270960 980235895 498158918 928430170 216003119 852570558 948400590 239257296 897053667 294741176 38297441 382677590 406314557 609468973 854148232 314532767 738191551 158215002 5865825 920471826 380037058 356271728 749175327 28319049 208101105 953758995 896570758 521930...

output:

39281
535950000 999989281

result:

wrong answer Result not equal to solution.