diff --git a/src/2/15/T178360.cpp b/src/2/15/T178360.cpp new file mode 100644 index 0000000..294989d --- /dev/null +++ b/src/2/15/T178360.cpp @@ -0,0 +1,3 @@ +int main(){ + +} \ No newline at end of file diff --git a/src/2/15/T316692.cpp b/src/2/15/T316692.cpp new file mode 100644 index 0000000..88596c6 --- /dev/null +++ b/src/2/15/T316692.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; +int main(){ + ios::sync_with_stdio(false); + cin.tie(0); + + int n, m, q; + cin >> n >> m >> q; + + vector> arr(n+1, vector(m+1, -1)); + + int x = 0, y = 0; + int dx = 1, dy = 1; + int t = 0; + + while (true){ + t++; + x += dx; + y += dy; + + if( (x == 0 || x == n) && (y == 0 || y == m)){ + if(arr[x][y] == -1){ + arr[x][y] = t; + } + break; + } + + if(arr[x][y] == -1){ + arr[x][y] = t; + } + + if(x == 0 || x == n){ + dx *= -1; + } + if(y == 0 || y == m){ + dy *= -1; + } + } + + while(q--){ + int qx, qy; + cin >> qx >> qy; + if(qx <0 || qx >n || qy <0 || qy >m){ + cout << "-1\n"; + continue; + } + cout << arr[qx][qy] << "\n"; + } +} \ No newline at end of file