답안 #734120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734120 2023-05-01T18:04:42 Z racsosabe 나머지들의 합 (NOI12_modsum) C++14
0 / 25
1 ms 440 KB
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;
const int N = 100000 + 5;

int add(int a, int b){
    return (a + b) % MOD;
}

int mul(long long a, long long b){
    return (a * b) % MOD;
}

int n;
long long L[N];
long long R[N];
bool vis[N][5][5];
int memo[N][5][5];

long long get_cnt(int rem, long long l, long long r){
    if(l % 5 <= rem) l += rem - l % 5;
    else l += rem - l % 5 + 5;
    if(r % 5 >= rem) r += rem - l % 5;
    else r += rem - l % 5 - 5;
    return l <= r ? (r - l) / 5 + 1 : 0;
}

int DP(int pos, int sum_sq, int sum){
	if(pos == n) return ((sum_sq + 1) * (sum_sq + 1) + 4) % 5 + 1;
	if(vis[pos][sum_sq][sum]) return memo[pos][sum_sq][sum];
	int res = 0;
	for(int x = 0; x < 5; x++){
		int new_sum_sq = (sum_sq + 2 * sum * x + x * x) % 5;
		int new_sum = (sum + x) % 5;
		long long Q = get_cnt(x, L[pos], R[pos]);
		res = add(res, mul(Q, DP(pos + 1, new_sum_sq, new_sum)));
	}
	vis[pos][sum_sq][sum] = true;
	return memo[pos][sum_sq][sum] = res;
}

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d %d", L + i, R + i);
	printf("%d\n", DP(0, 0, 0));
	return 0;
}

Compilation message

modsum.cpp: In function 'int main()':
modsum.cpp:45:37: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   45 |  for(int i = 0; i < n; i++) scanf("%d %d", L + i, R + i);
      |                                    ~^      ~~~~~
      |                                     |        |
      |                                     int*     long long int*
      |                                    %lld
modsum.cpp:45:40: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   45 |  for(int i = 0; i < n; i++) scanf("%d %d", L + i, R + i);
      |                                       ~^          ~~~~~
      |                                        |            |
      |                                        int*         long long int*
      |                                       %lld
modsum.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
modsum.cpp:45:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  for(int i = 0; i < n; i++) scanf("%d %d", L + i, R + i);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 440 KB Output isn't correct
2 Halted 0 ms 0 KB -