sysy-data/performance_c/sy/transpose2.sy

52 lines
999 B
Plaintext
Raw Permalink Normal View History

2024-04-14 22:20:29 +08:00
int matrix[20000000];
int a[100000];
2024-08-10 14:32:48 +08:00
int transpose(int n, int matrix[], int rowsize){
2024-04-14 22:20:29 +08:00
int colsize = n / rowsize;
int i = 0;
int j = 0;
2024-08-10 14:32:48 +08:00
while (i < colsize){
2024-04-14 22:20:29 +08:00
j = 0;
2024-08-10 14:32:48 +08:00
while (j < rowsize){
if (i < j){
2024-04-14 22:20:29 +08:00
j = j + 1;
continue;
}
int curr = matrix[i * rowsize + j];
matrix[j * colsize + i] = matrix[i * rowsize + j];
matrix[i * rowsize + j] = curr;
j = j + 1;
}
i = i + 1;
}
return -1;
}
2024-08-10 14:32:48 +08:00
int main(){
2024-04-14 22:20:29 +08:00
int n = getint();
int len = getarray(a);
starttime();
int i = 0;
2024-08-10 14:32:48 +08:00
while (i < n){
2024-04-14 22:20:29 +08:00
matrix[i] = i;
i = i + 1;
}
i = 0;
2024-08-10 14:32:48 +08:00
while (i < len){
2024-04-14 22:20:29 +08:00
transpose(n, matrix, a[i]);
i = i + 1;
}
int ans = 0;
i = 0;
2024-08-10 14:32:48 +08:00
while (i < len){
2024-04-14 22:20:29 +08:00
ans = ans + i * i * matrix[i];
i = i + 1;
}
2024-08-10 14:32:48 +08:00
if (ans < 0) ans = -ans;
2024-04-14 22:20:29 +08:00
stoptime();
putint(ans);
putch(10);
return 0;
2024-08-10 14:32:48 +08:00
2024-04-14 22:20:29 +08:00
}