| Task: | Ruudukko | 
| Sender: | Turtleb01 | 
| Submission time: | 2022-11-02 20:21:24 +0200 | 
| Language: | C++ (C++17) | 
| Status: | READY | 
| Result: | 100 | 
| group | verdict | score | 
|---|---|---|
| #1 | ACCEPTED | 28 | 
| #2 | ACCEPTED | 33 | 
| #3 | ACCEPTED | 39 | 
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details | 
| #2 | ACCEPTED | 0.01 s | 1, 2, 3 | details | 
| #3 | ACCEPTED | 0.01 s | 1, 2, 3 | details | 
| #4 | ACCEPTED | 0.01 s | 2, 3 | details | 
| #5 | ACCEPTED | 0.01 s | 2, 3 | details | 
| #6 | ACCEPTED | 0.01 s | 2, 3 | details | 
| #7 | ACCEPTED | 0.07 s | 3 | details | 
| #8 | ACCEPTED | 0.12 s | 3 | details | 
| #9 | ACCEPTED | 0.26 s | 3 | details | 
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:11:7: warning: unused variable 'a' [-Wunused-variable]
   11 |   int a;
      |       ^
input/code.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~Code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main() {
  int n;
  scanf("%d",&n);
  int mod = 1e9+7;
  int a;
  long b=0;
  int cur, prevsize;
  int build=0;
  int *table[1000001L] = {NULL};
  getchar();
  while(b<(n*n)) {
    cur = getchar();
    if(cur==' '||cur=='\n') {
      if(table[build]) {
        prevsize = table[build][0];
        table[build]= (int *) realloc(table[build],sizeof(int)*(prevsize+2));
        if(!table[build]) printf("error with realloc");
        table[build][0]=prevsize+1;
        table[build][prevsize+1]=b;
      } else {
        table[build]= (int *) malloc(sizeof(int)*2);
        table[build][0]=1;
        table[build][1]=b;
      }
      b++;
      build=0;
    } else {
      build*=10;
      build+=cur-'0';
    }
  }
  unsigned long finalcount = 0;
  unsigned long xpaths[1000] = {0}, ypaths[1000] = {0};
  unsigned long *newpaths;
  unsigned long i, pathc;
  unsigned long j, k, index;
  short x, y;
  for(i=0;i<=1000000L;i++) {
    if(table[i]) {
      k=table[i][0];
      newpaths = (long unsigned int *) malloc(sizeof(long)*k*3);
//      printf("kana %d\n",table[i][k]);
      for(j=0;j<k;j++) {
        index = table[i][j+1];
        x = index%n;
        y = index/n;
        pathc = (1+xpaths[x]+ypaths[y])%mod;
        newpaths[j*3]=pathc;
        newpaths[j*3+1]=x;
        newpaths[j*3+2]=y;
        finalcount=(finalcount+pathc)%mod;
      }
      for(j=0;j<k;j++) {
        pathc=newpaths[j*3];
        xpaths[newpaths[j*3+1]]+=pathc;
        ypaths[newpaths[j*3+2]]+=pathc;
      }
      free(newpaths);
    }
  }
//  printf("%u\n",UINT_MAX);
//  for(i=0;i<1000000;i++) {
//    finalcount=(finalcount+paths[i])%mod;
//  }
  printf("%lu\n",finalcount);
}
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
| input | 
|---|
| 3 1 1 1 1 1 1 1 1 1  | 
| correct output | 
|---|
| 9 | 
| user output | 
|---|
| 9 | 
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
| input | 
|---|
| 3 1 2 3 6 5 4 7 8 9  | 
| correct output | 
|---|
| 135 | 
| user output | 
|---|
| 135 | 
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
| input | 
|---|
| 3 7 8 1 4 5 4 3 9 6  | 
| correct output | 
|---|
| 57 | 
| user output | 
|---|
| 57 | 
Test 4
Group: 2, 3
Verdict: ACCEPTED
| input | 
|---|
| 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...  | 
| correct output | 
|---|
| 10000 | 
| user output | 
|---|
| 10000 | 
Test 5
Group: 2, 3
Verdict: ACCEPTED
| input | 
|---|
| 100 1 2 3 4 5 6 7 8 9 10 11 12 13 ...  | 
| correct output | 
|---|
| 187458477 | 
| user output | 
|---|
| 187458477 | 
Test 6
Group: 2, 3
Verdict: ACCEPTED
| input | 
|---|
| 100 2995 8734 1018 2513 7971 5063 ...  | 
| correct output | 
|---|
| 964692694 | 
| user output | 
|---|
| 964692694 | 
Test 7
Group: 3
Verdict: ACCEPTED
| input | 
|---|
| 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...  | 
| correct output | 
|---|
| 1000000 | 
| user output | 
|---|
| 1000000 | 
Test 8
Group: 3
Verdict: ACCEPTED
| input | 
|---|
| 1000 1 2 3 4 5 6 7 8 9 10 11 12 13 ...  | 
| correct output | 
|---|
| 229147081 | 
| user output | 
|---|
| 229147081 | 
Test 9
Group: 3
Verdict: ACCEPTED
| input | 
|---|
| 1000 520283 805991 492643 75254 527...  | 
| correct output | 
|---|
| 951147313 | 
| user output | 
|---|
| 951147313 | 
