Submission #3409369


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const long long kmaxN = 10 + 5;
const long long kmaxM = 10 + 5;

struct Matrix {
	long long n, m;
	long long data[kmaxN][kmaxM];
	
	void Init(long long n = 0, long long m = 0) {
		memset(data, 0, sizeof(data));
		this->n = n;
		this->m = m;
		return ;
	}
	
	void Init_identity(long long n = 0, long long m = 0) {
		if (n || m) {
			Init(n, m);
		} else {
			memset(data, 0, sizeof(data));
		}
		if (n != m) return ; //ERROR
		for(long long i = 1; i <= n; i++)
			data[i][i] = 1;
		return ;
	}
	
} A, B;

Matrix Multiply(const Matrix& A, const Matrix& B) {
	Matrix C;
	C.Init(A.n, B.m);
	if (A.m != B.n) return C; //ERROR
	for(long long i = 1; i <= C.n; i++)
		for(long long j = 1; j <= C.m; j++)
			for(long long k = 1; k <= A.m; k++)
				C.data[i][j] += A.data[i][k] * B.data[k][j];
	return C;
}

int main() {
	long long n;
	scanf("%d", &n);
	if (n == 0) {
		printf("1\n");
		return 0;
	}
	A.Init(2, 2);
	A.data[1][1] = 0; A.data[1][2] = 1;
	A.data[2][1] = 1; A.data[2][2] = 1;
	B.Init_identity(2, 2);
	long long k = n - 1;
	while(k) {
		if (k & 1) B = Multiply(A, B);
		A = Multiply(A, A);
		k >>= 1;
	}
	A.Init(1, 2);
	A.data[1][1] = 1; A.data[1][2] = 2;
	B = Multiply(A, B);
	printf("%d\n", B.data[1][1]);
	return 0;
}

Submission Info

Submission Time
Task A - 算盤の書
User luogu_bot3
Language C++ (GCC 5.4.1)
Score 100
Code Size 1300 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:46:16: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
  scanf("%d", &n);
                ^
./Main.cpp:64:29: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
  printf("%d\n", B.data[1][1]);
                             ^
./Main.cpp:46:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 46
Set Name Test Cases
All 00_sample1, 00_sample2, 00_sample3, 10_testcase00, 10_testcase01, 10_testcase02, 10_testcase03, 10_testcase04, 10_testcase05, 10_testcase06, 10_testcase07, 10_testcase08, 10_testcase09, 10_testcase10, 10_testcase11, 10_testcase12, 10_testcase13, 10_testcase14, 10_testcase15, 10_testcase16, 10_testcase17, 10_testcase18, 10_testcase19, 10_testcase20, 10_testcase21, 10_testcase22, 10_testcase23, 10_testcase24, 10_testcase25, 10_testcase26, 10_testcase27, 10_testcase28, 10_testcase29, 10_testcase30, 10_testcase31, 10_testcase32, 10_testcase33, 10_testcase34, 10_testcase35, 10_testcase36, 10_testcase37, 10_testcase38, 10_testcase39, 10_testcase40, 10_testcase41, 10_testcase42
Case Name Status Exec Time Memory
00_sample1 AC 1 ms 256 KB
00_sample2 AC 1 ms 256 KB
00_sample3 AC 1 ms 256 KB
10_testcase00 AC 1 ms 256 KB
10_testcase01 AC 1 ms 256 KB
10_testcase02 AC 1 ms 256 KB
10_testcase03 AC 1 ms 256 KB
10_testcase04 AC 1 ms 256 KB
10_testcase05 AC 1 ms 256 KB
10_testcase06 AC 1 ms 256 KB
10_testcase07 AC 1 ms 256 KB
10_testcase08 AC 1 ms 256 KB
10_testcase09 AC 1 ms 256 KB
10_testcase10 AC 1 ms 256 KB
10_testcase11 AC 1 ms 256 KB
10_testcase12 AC 1 ms 256 KB
10_testcase13 AC 1 ms 256 KB
10_testcase14 AC 1 ms 256 KB
10_testcase15 AC 1 ms 256 KB
10_testcase16 AC 1 ms 256 KB
10_testcase17 AC 1 ms 256 KB
10_testcase18 AC 1 ms 256 KB
10_testcase19 AC 1 ms 256 KB
10_testcase20 AC 1 ms 256 KB
10_testcase21 AC 1 ms 256 KB
10_testcase22 AC 1 ms 256 KB
10_testcase23 AC 1 ms 256 KB
10_testcase24 AC 1 ms 256 KB
10_testcase25 AC 1 ms 256 KB
10_testcase26 AC 1 ms 256 KB
10_testcase27 AC 1 ms 256 KB
10_testcase28 AC 1 ms 256 KB
10_testcase29 AC 1 ms 256 KB
10_testcase30 AC 1 ms 256 KB
10_testcase31 AC 1 ms 256 KB
10_testcase32 AC 1 ms 256 KB
10_testcase33 AC 1 ms 256 KB
10_testcase34 AC 1 ms 256 KB
10_testcase35 AC 1 ms 256 KB
10_testcase36 AC 1 ms 256 KB
10_testcase37 AC 1 ms 256 KB
10_testcase38 AC 1 ms 256 KB
10_testcase39 AC 1 ms 256 KB
10_testcase40 AC 1 ms 256 KB
10_testcase41 AC 1 ms 256 KB
10_testcase42 AC 1 ms 256 KB