669C - Little Artem and Matrix - CodeForces Solution


constructive algorithms implementation *1400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

// -----------------------------------------------------------------

void test(){
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

// -----------------------------------------------------------------

#define FastIO        cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
#define printv(v)     for(auto x:v){cout<<x<<" ";}cout<<endl;
#define dbg(x)        cout<<#x<<" = "<<x<<endl;
#define SQ(a)         (a)*(a)
#define PB            push_back
#define S             second
#define F             first


// -----------------------------------------------------------------

typedef pair<int,int>     ii;

typedef vector<int>       vi;
typedef vector<ii>        vii;

typedef vector<vi>        mi;
typedef vector<vii>       mii;

// --------------------------------------

typedef long long       ll;

typedef pair<ll, ll>   pll;

typedef vector< ll >    vll;
typedef vector< pll >   vpll;

typedef vector< vll >   mll;
typedef vector< vpll >   mpll;

typedef unsigned long long       ull;
typedef long double     ld;

// --------------------------------------

const ll INF = 9223372036854775807;
const int OO = 2147483647;
const ll MOD = 998244353;
const ld EPS = 1e-9;
const ld PI  = 3.141592653589793238;

const int TOW = 0b10;
const int FIFTEEN = 0xf;

int tc = 1;

// -----------------------------------------------------------------

const int N = 3e5 + 5e3;

ll n, m, q, t, r, c, x;
stack<pair<ii,ii>> v;
int ans[105][105];

// --------------------------------------

void row(int i){
    int z = ans[i][m-1]; 
    for(int j = m-1 ; j > 0 ; j --) ans[i][j] = ans[i][j-1];
    ans[i][0] = z;
}

void col(int j){
    int z = ans[n-1][j];
    for(int i = n-1 ; i > 0 ; i --) ans[i][j] = ans[i-1][j];
    ans[0][j] = z;
}

// --------------------------------------

void doTest(){
    cin>>n>>m>>q;
    for(int i = 0 ; i < q ; i ++){
        cin>>t;
        if(t == 3){
            cin>>r>>c>>x; r--; c--;
            v.push({{t, r}, {c, x}});
        }else{
            cin>>x; x--;
            v.push({{t, x}, {0, 0}});
        }
    }
    while(!v.empty()){
        pair<ii,ii> k = v.top(); v.pop();
        if(k.F.F == 1) row(k.F.S);
        else if(k.F.F == 2) col(k.F.S);
        else if(k.F.F == 3) ans[k.F.S][k.S.F] = k.S.S;
    }
    for(int i = 0 ; i < n ; i ++){
        for(int j = 0 ; j < m ; j ++)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}


// --------------------------------------

int main(){
    test();
    FastIO
    cout<<fixed<<setprecision(15);

    // scanf("%d", &tc);
    // cin>>tc;
    while(tc--) doTest();
}


// -----------------------------------------------------------------


Comments

Submit
0 Comments
More Questions

1920. Build Array from Permutation
494. Target Sum
797. All Paths From Source to Target
1547B - Alphabetical Strings
1550A - Find The Array
118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes
36. Valid Sudoku
557. Reverse Words in a String III
566. Reshape the Matrix
167. Two Sum II - Input array is sorted
387. First Unique Character in a String
383. Ransom Note
242. Valid Anagram
141. Linked List Cycle
21. Merge Two Sorted Lists
203. Remove Linked List Elements
733. Flood Fill
206. Reverse Linked List
83. Remove Duplicates from Sorted List
116. Populating Next Right Pointers in Each Node
145. Binary Tree Postorder Traversal
94. Binary Tree Inorder Traversal
101. Symmetric Tree
77. Combinations
46. Permutations
226. Invert Binary Tree