CSES - Datatähti 2023 alku - Results
Submission details
Task:Ruudukko
Sender:Turtleb01
Submission time:2022-11-02 20:19:15 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:22:29: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   22 |         table[build]=realloc(table[build],sizeof(int)*(prevsize+2));
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                             |
      |                             void*
input/code.cpp:27:28: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   27 |         table[build]=malloc(sizeof(int)*2);
      |                      ~~~~~~^~~~~~~~~~~~~~~
      |                            |
      |                            void*
input/code.cpp:48:24: error: invalid conversion from 'void*' to 'long unsigned int*' [-fpermissive]
   48 |       newpaths = malloc(sizeof(long)*k*3);
      |                  ~~~~~~^~~~~~~~~~~~~~~~~~
      |                        |
      |                        void*
input/code.cpp:11:7: warning: unused variable 'a' [-Wunused-variable]
   11 |   int a;
      |...

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]=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]=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 = 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);
}