# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
83506 | charlies_moo | Spirale (COCI18_spirale) | C++14 | 57 ms | 588 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <iostream>
# include <fstream>
using namespace std;
int main(){
istream &fin = cin;
ostream &fout = cout;
int n, m, k, inf, x, y, t, i, j, p;
fin >> n >> m >> k;
inf = n * m * 10;
int arr[n][m];
for(i=0;i<n;i++){
for(j=0;j<m;j++){
arr[i][j] = inf;
}
}
for(p=1;p<=k;p++){
int num, counter, length, direction;
num = 1;
length = 1;
direction = -1;
fin >> x >> y >> t;
x -= 1;
y -= 1;
if(t==0){
t=1;
}
else{
t=-1;
}
arr[x][y] = num;
counter = 1;
while(counter < (n * m)){
for(i=1;i<=length;i++){
num += 1;
x += direction;
if(x<0||x>=n||y<0||y>=m){
continue;
}
if(arr[x][y] > num){
arr[x][y] = num;
}
counter += 1;
}
direction = 0 - direction;
for(i=1;i<=length;i++){
num += 1;
y += direction * t;
if(x<0||x>=n||y<0||y>=m){
continue;
}
if(arr[x][y] > num){
arr[x][y] = num;
}
counter += 1;
}
length += 1;
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
fout << arr[i][j] << " ";
}
fout << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |