Submission #27696613


Source Code Expand

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")

const int MOD = (1e9+7);
void printmat(const vector<vector<int>>& mat) {
    for (auto row : mat) {
        for (auto elem : row)
            cout << elem << " ";
        cout << endl;
    }
}
void printv(const vector<int>& v) {
    for (auto elem : v)
        cout << elem << " ";
    cout << endl;
}
void printd(const deque<int>& v) {
    for (auto elem : v)
        cout << elem << " ";
    cout << endl;
}
void printvp(const vector<pair<int,int>>& vp) {
    for (auto pr : vp) {
        cout << pr.first << ", " << pr.second;
        cout << endl;
    }
}
void printvs(const vector<set<int>>& vs) {
    for (auto row : vs) {
        for (auto elem : row)
            cout << elem << ", ";
        cout << endl;
    }
}
void printht(const unordered_map<int, int>& ht) {
    for (auto elem : ht)
        cout << elem.first << " : " << elem.second << endl;
}
void printmp(const map<int, int>& ht) {
    for (auto elem : ht)
        cout << elem.first << " : " << elem.second << endl;
}
void printst(const set<int>& st) {
    for (auto elem : st)
        cout << elem << " ";
    cout << endl;
}
 
bool isPrime(long long n) {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (long long i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
 
map<long long, long long> primeFactors(long long n) {
    map<long long, long long> ans;
    while (n % 2 == 0) {
        ans[2]++;
        n = n/2;
    }
    for (long long i = 3; i*i <= (n); i = i + 2) {
        while (n % i == 0) {
            ans[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        ans[n]++;
    return ans;
}
 
int find_f(const vector<int>& uf, int i) {
    while (uf[i]!=i)
        i = uf[i];
    return i;
}
bool union_f(vector<int>& uf, vector<int>& sz, int a, int b) {
    a = find_f(uf, a);
    b = find_f(uf, b);
    //cout << "a, b = " << a << ", " << b << endl;
    if (a==b) return false;
    if (sz[a] < sz[b]) {
        //cout << "sz[a], sz[b] = " << sz[a] << ", " << sz[b] << endl;
        //cout << "a, b = " << a << ", " << b << endl;
        swap(a,b);
        //cout << "a, b = " << a << ", " << b << endl;
    }
    sz[a] += sz[b];
    uf[b] = a;
    return true;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
    int T=1, caseIdx=0;
    //cin >> T;
    while (T--) {
        //caseIdx++;
        int n;
        cin >> n;
        int m = 6+n%6;
        vector<vector<char>> mat(m, vector<char>(m, '.'));
        switch (m) {
            case 6:
                for (int i=0; i<m; i++) {
                    for (int j=0; j<m; j++) {
                        //cout << "i,j = " << i << " " << j << endl;
                        if (i<3 && j%2==0)
                            mat[i][j] = '#';
                        else if (i>=3 && j%2==1)
                            mat[i][j] = '#';
                    }
                }                
                break;
            case 7: 
                {
                    vector<pair<int,int>> vp {{0,0},{0,2},{0,4},{1,0},{1,2},{1,4},{2,0},{2,2},{2,5},{3,1},{3,3},{3,5},{4,1},{4,3},{4,6},{5,1},{5,3},{5,6},{6,4},{6,5},{6,6}};
                    for (pair<int,int>& pr : vp) {
                        mat[pr.first][pr.second] = '#'; 
                    }
                }
                break;
            case 8:
                {
                    vector<pair<int,int>> vp {{0,1},{0,4},{0,5},{1,1},{1,4},{1,5},{2,0},{2,2},{2,3},{3,0},{3,2},{3,3},{4,0},{4,6},{4,7},{5,1},{5,2},{5,3},{6,6},{6,7},{7,4},{6,5},{7,6},{7,7}};
                    //cout << "vp.size() = " << vp.size() << endl;
                    for (pair<int,int>& pr : vp) {
                        mat[pr.first][pr.second] = '#'; 
                    }
                }                
                break;
            case 9:
                {
                    vector<pair<int,int>> vp {{0,1},{0,4},{0,5},{1,1},{1,4},{1,6},{2,0},{2,2},{2,3},{3,0},{3,2},{3,3},{4,0},{4,8},{4,7},{5,1},{5,2},{5,3},{6,6},{6,7},{7,4},{6,5},{7,5},{7,8},{8,6},{8,7},{8,8}};
                    //cout << "vp.size() = " << vp.size() << endl;
                    for (pair<int,int>& pr : vp) {
                        mat[pr.first][pr.second] = '#'; 
                    }
                }                    
                break;
            case 10:
                {
                    vector<pair<int,int>> vp {{0,1},{0,4},{0,5},{1,1},{1,4},{1,8},{2,0},{2,2},{2,3},{3,0},{3,2},{3,3},{4,0},{4,8},{4,9},{5,1},{5,2},{5,3},{6,6},{6,9},{7,4},{6,5},{7,6},{7,7},{8,6},{8,7},{8,5},{9,7},{9,8},{9,9}};
                    //cout << "vp.size() = " << vp.size() << endl;
                    for (pair<int,int>& pr : vp) {
                        mat[pr.first][pr.second] = '#'; 
                    }
                }                    
                break;
            case 11:
                {
                    vector<pair<int,int>> vp {{0,1},{0,4},{0,5},{1,1},{1,4},{1,8},{2,0},{2,2},{2,3},{3,0},{3,2},{3,3},{4,0},{4,10},{4,9},{5,1},{5,2},{5,3},{6,6},{6,9},{7,4},{6,5},{7,6},{7,9},{8,6},{8,7},{8,5},{9,7},{9,8},{9,10},{10,8},{10,7},{10,10}};
                    //cout << "vp.size() = " << vp.size() << endl;
                    for (pair<int,int>& pr : vp) {
                        mat[pr.first][pr.second] = '#'; 
                    }
                }                    
                break;
        }
        
#if 1        
        for (int i=0; i<m; i++) {
            int cnt = 0;
            for (int j=0; j<m; j++) 
                if (mat[i][j]=='#')
                    cnt++;
            if (cnt!=3)
                cout << "Error!\n";
        }
        for (int j=0; j<m; j++)  {
            int cnt = 0;
            for (int i=0; i<m; i++)
                if (mat[i][j]=='#')
                    cnt++;
            if (cnt!=3)
                cout << "Error!\n";
        }
#endif        
        vector<vector<char>> tbl(n, vector<char>(n, '.'));
        int k;
        for (k=0; k<(n-6)/6; k++) {
            for (int i=0; i<6; i++) {
                for (int j=0; j<6; j++) {
                    if (i<3 && j%2==0)
                        tbl[i+k*6][j+k*6] = '#';
                    else if (i>=3 && j%2==1)
                        tbl[i+k*6][j+k*6] = '#';                    
                }
            }
        }
        //cout << "k = " << k << endl;
        for (int i=0; i<m; i++) {
            for (int j=0; j<m; j++) {
                tbl[i+k*6][j+k*6] = mat[i][j];
            }
        }
        
#if 0 
        for (int i=0; i<n; i++) {
            int cnt = 0;
            for (int j=0; j<n; j++) 
                if (tbl[i][j]=='#')
                    cnt++;
            if (cnt!=3)
                cout << "Error!\n";
        }
        for (int j=0; j<n; j++)  {
            int cnt = 0;
            for (int i=0; i<n; i++)
                if (tbl[i][j]=='#')
                    cnt++;
            if (cnt!=3)
                cout << "Error!\n";
        }
#endif            

        for (auto& row : tbl) {
            for (auto& c : row)
                cout << c;
            cout << "\n";
        }
        //cout << "Case #" << caseIdx << ": " << s << endl;
    }
}
 
 

Submission Info

Submission Time
Task A - Three Cells per Row and Column
User llc5pg
Language C++ (GCC 9.2.1)
Score 300
Code Size 7651 Byte
Status AC
Exec Time 18 ms
Memory 3768 KiB

Compile Error

./Main.cpp:5: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
./Main.cpp: In function ‘int main()’:
./Main.cpp:106:14: warning: unused variable ‘caseIdx’ [-Wunused-variable]
  106 |     int T=1, caseIdx=0;
      |              ^~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 1
AC × 24
Set Name Test Cases
Sample 00-sample-001.txt
All 00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 13 ms 3512 KiB
01-001.txt AC 1 ms 3536 KiB
01-002.txt AC 2 ms 3556 KiB
01-003.txt AC 1 ms 3500 KiB
01-004.txt AC 1 ms 3460 KiB
01-005.txt AC 2 ms 3624 KiB
01-006.txt AC 2 ms 3464 KiB
01-007.txt AC 4 ms 3624 KiB
01-008.txt AC 6 ms 3636 KiB
01-009.txt AC 4 ms 3696 KiB
01-010.txt AC 5 ms 3556 KiB
01-011.txt AC 8 ms 3740 KiB
01-012.txt AC 2 ms 3472 KiB
01-013.txt AC 2 ms 3536 KiB
01-014.txt AC 11 ms 3700 KiB
01-015.txt AC 7 ms 3544 KiB
01-016.txt AC 13 ms 3700 KiB
01-017.txt AC 12 ms 3660 KiB
01-018.txt AC 18 ms 3640 KiB
01-019.txt AC 13 ms 3740 KiB
01-020.txt AC 12 ms 3640 KiB
01-021.txt AC 15 ms 3768 KiB
01-022.txt AC 12 ms 3660 KiB
01-023.txt AC 12 ms 3768 KiB