結果

問題 No.466 ジオラマ
ユーザー vjudge1
提出日時 2025-06-20 16:35:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 3,103 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 212,504 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 16:35:34
合計ジャッジ時間 6,566 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 83
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
bool st;
using namespace std;
template<typename T>istream&operator>>(istream&I,vector<T>&v){for(auto&i:v)I>>i;return I;}
template<typename T>ostream&operator<<(ostream&O,vector<T> v){for(auto i:v)O<<i<<' ';return O;}
string TMP,STR;
stringstream CIN;
void read_all(){
#ifdef debug
	cerr<<"----------------------------------- START -----------------------------------\n";
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	while(getline(cin,TMP))STR+=TMP,STR+='\n';
	CIN.str(STR);
	cerr<<"\n--------------------------------- INPUT END ---------------------------------\n";
#endif
}
#ifdef debug
#define cin CIN
#endif
namespace AC{
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))

void solve() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    bool impossible = false;
    vector<pair<int, int> > e;
    if (a == c and b == c) {
        if (c == 1) impossible = true;
        repeat (i,c) e.emplace_back(i, (i+1)%c);
    } else {
        int A = 1000000;
        int B = 2000000;
        int C = 3000000;
        map<int,int> tr;
        if (c == 0) {
			for(int i=0;i<a-1;i++)e.emplace_back(A+i, A+i+1);
			for(int i=0;i<b-1;i++)e.emplace_back(B+i, B+i+1);
        } else {
			for(int i=0;i<a-c;i++)e.emplace_back(A+i, A+i+1);
			for(int i=0;i<b-c;i++)e.emplace_back(B+i, B+i+1);
			for(int i=0;i<c-1;i++)e.emplace_back(C+i, C+i+1);
            if (a == c) A = C;
            if (b == c) B = C;
            tr[A+a-c] = C;
            tr[B+b-c] = C;
        }
        map<int,int> compress;
        compress[A] = 0;
        compress[B] = 1;
        auto name = [&](int & i) {
            if (tr.count(i)) i = tr[i];
            if (not compress.count(i)) { int size = compress.size(); compress[i] = size; }
            i = compress[i];
        };
        for (auto & it : e) {
            name(it.first);
            name(it.second);
        }
    }
    if (impossible or e.size() > d) {
        cout << -1 << endl;
    } else {
        cout << a+b-c << ' ' << e.size() << endl;
        for (auto it : e) cout << it.first << ' ' << it.second << endl;
    }
}
}
bool ed;
signed main(){
	chrono::steady_clock::time_point St=chrono::steady_clock::now();
	read_all();
	chrono::steady_clock::time_point ST=chrono::steady_clock::now();
	int t=1;
	//cin>>t;
	while(t--)AC::solve();
	chrono::steady_clock::time_point ED=chrono::steady_clock::now();
	cerr<<setprecision(3)<<fixed<<"\n\n------------------------------------ END ------------------------------------\n"<<"Total Time   : "<<left<<setw(10)<<chrono::duration_cast<chrono::milliseconds>(ED-St).count()<<" \tms\n"<<"Real  Time   : "<<left<<setw(10)<<chrono::duration_cast<chrono::milliseconds>(ED-ST).count()<<" \tms\n"<<"             : "<<left<<setw(10)<<chrono::duration_cast<chrono::microseconds>(ED-ST).count()<<" \t?s\n\n"<<"Total Memory : "<<left<<setw(10)<<(&ed-&st)/1048576.0<<" \tMB\n"<<"               "<<left<<setw(10)<<(&ed-&st)/1024.0<<" \tKB\n"<<"               "<<left<<setw(10)<<(&ed-&st)<<" \tByte\n";
}
0