Submission #198433

# Submission time Handle Problem Language Result Execution time Memory
198433 2020-01-26T02:54:16 Z model_code W (RMI18_w) C
30 / 100
8 ms 380 KB
/**
 * Method: Direct formula for the case of all distinct elements.
 *
 * Author: Catalin Francu
 **/
#include <stdio.h>

#define MOD 1000000007
#define HALF 500000004 /* inverse of 2 modulo MOD */

typedef unsigned long long u64;

u64 power(int a, int n) {
  u64 result = 1;
  while (n--) {
    result = result * a % MOD;
  }
  return result;
}

int main() {
  /* read input data; we only care about n */
  int n;
  scanf("%d", &n);

  /* result = 2^(2 * n - 3) - n * 2^(n - 2) - (3^n + 7) / 2 + n + 6 * 2^(n - 2) */
  u64 x = power(2, n - 2);
  u64 y = power(3, n);
  u64 result = (2 * x * x % MOD
                + (MOD - n * x % MOD)
                + (MOD - HALF * (y + 7) % MOD)
                + n + 6 * x
                ) % MOD;

  printf("%llu\n", result);
}

Compilation message

w.c: In function 'main':
w.c:24:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Incorrect 6 ms 376 KB Output isn't correct
4 Incorrect 7 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 7 ms 256 KB Output is correct
5 Correct 8 ms 256 KB Output is correct
6 Correct 8 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Incorrect 5 ms 380 KB Output isn't correct
3 Incorrect 5 ms 256 KB Output isn't correct
4 Incorrect 6 ms 256 KB Output isn't correct
5 Incorrect 5 ms 256 KB Output isn't correct
6 Incorrect 5 ms 256 KB Output isn't correct
7 Incorrect 5 ms 256 KB Output isn't correct
8 Incorrect 6 ms 256 KB Output isn't correct
9 Incorrect 7 ms 256 KB Output isn't correct
10 Incorrect 7 ms 256 KB Output isn't correct